From b5580a1164fd0d3ab3a61ffcce947c49a75fd377 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 01:55:42 +0000 Subject: [PATCH 01/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 630ddb2..d19248c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 8b12a7835598d112c117a5e5468c41d423c3ff61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 01:56:55 +0000 Subject: [PATCH 02/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 39 files changed, 6208 insertions(+), 4805 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 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v1 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6c3d75f..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array and assigns elements to a provided - output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 3f29290..7b6b965 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index d19248c..402ce39 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cac1d78 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 7bd607aba523a8adf35dd5008bfff85d76342280 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 27 Jul 2023 05:07:49 +0000 Subject: [PATCH 03/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 630ddb2..d19248c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 28cf871925eb0dfa9d1c82c0aa16b46130068119 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 27 Jul 2023 05:08:17 +0000 Subject: [PATCH 04/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 7b6b965..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/object'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arry - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cac1d78..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 26ecb193b607aa65644e38e4e8907619fa101961 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 27 Jul 2023 05:09:17 +0000 Subject: [PATCH 05/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 39 files changed, 6208 insertions(+), 4805 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 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6c3d75f..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array and assigns elements to a provided - output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5ea2a65..85611d2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index d19248c..402ce39 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..db66629 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From f0de3461e469702ef6e81de4fdd6845462513572 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 04:18:21 +0000 Subject: [PATCH 06/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 630ddb2..d19248c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f712c1ae093aa8c147656d5d09a2750c6824f4ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 04:18:53 +0000 Subject: [PATCH 07/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 85611d2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/object'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index db66629..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4ba7d13ae3d58c8a2e1696a9baa783eda383a1da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 04:19:38 +0000 Subject: [PATCH 08/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 39 files changed, 6208 insertions(+), 4805 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 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5ea2a65..85611d2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index d19248c..402ce39 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5b0ddff --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From dec320d6348ec75c510cd4c80b9d65756b6d4d75 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 15:00:31 +0000 Subject: [PATCH 09/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d5041..6f9f469 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 80b899008e5f0d69a7cf48d50bbd7b044f80f222 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 15:00:58 +0000 Subject: [PATCH 10/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 85611d2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/object'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5b0ddff..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3d8c3cbc860950e1929d2d4da8c10d12a141d1c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 15:01:51 +0000 Subject: [PATCH 11/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 39 files changed, 6208 insertions(+), 4805 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 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5ea2a65..85611d2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 6f9f469..09b8a1d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2da0f22 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 1a6260617d34825d4744d9da0d2328939cbec396 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 15:02:21 +0000 Subject: [PATCH 12/99] Update README.md for ESM bundle v0.0.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab9ae0c..a79b465 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,13 @@ limitations under the License. ## Usage ```javascript -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -150,7 +150,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 6485761bd1bd27d2e30d568a2c23fd698c2ae64c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 29 Jul 2023 15:02:22 +0000 Subject: [PATCH 13/99] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a79b465..ceb5170 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ limitations under the License. ## Usage +```javascript +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@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/array-base-flatten2d-by/tags). For example, + ```javascript import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; ``` @@ -39,7 +44,7 @@ import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatte You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -150,7 +155,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.0.1-esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 7a2666257d174c776da91c6e2fd1d55a4808c7c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 17 Aug 2023 02:22:37 +0000 Subject: [PATCH 14/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d5041..6f9f469 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From eda1ebe4c2fb4ed5ac12604ae05a7124d0d67d33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 17 Aug 2023 02:31:51 +0000 Subject: [PATCH 15/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 85611d2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/object'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2da0f22..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 11e8fc6ea730a336a4dd2a1682c6145ca0534362 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 17 Aug 2023 02:32:41 +0000 Subject: [PATCH 16/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 42 files changed, 6208 insertions(+), 4807 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 6dded27..49363e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 6f9f469..09b8a1d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e0d95fb --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From ad3177269fd1368f7bb31ba5deea185f4c23c92b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 10:09:02 +0000 Subject: [PATCH 17/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d5041..6f9f469 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 573450956eacf0631a17a873c34e8eb92892fde7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 10:18:57 +0000 Subject: [PATCH 18/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 49363e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/array'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e0d95fb..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 69e966e676864aa71d750504e55182b03de76007 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 10:19:37 +0000 Subject: [PATCH 19/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 42 files changed, 6208 insertions(+), 4807 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 6045b5e..1799769 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 6f9f469..09b8a1d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a9a30a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From ce3bf56f04443b02be235af9bbfe1c61d75afbf4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 21:40:34 +0000 Subject: [PATCH 20/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d5041..6f9f469 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5999f0c70f3a074352b232032f018b79c2a86154 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 21:43:43 +0000 Subject: [PATCH 21/99] Remove files --- index.d.ts | 198 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6380 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 1799769..0000000 --- a/index.d.ts +++ /dev/null @@ -1,198 +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 { Collection } from '@stdlib/types/array'; - -/** -* Two-dimensional nested array. -*/ -type Array2D = Array>; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Collection, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Collection, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a9a30a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 172455fcda75e4f0967e4556018b8f0b169e07b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 24 Aug 2023 21:44:23 +0000 Subject: [PATCH 22/99] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 42 files changed, 6208 insertions(+), 4807 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 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..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 `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 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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 +217,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 6f9f469..09b8a1d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-float64array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..542a9e9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 873d4b1f5703de79c6b70722158f0d15ba58ef7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 06:44:10 +0000 Subject: [PATCH 23/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce971bb..432a101 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-base-filled": "^0.0.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 3eac06b435aba7db5d15dd5b01e2de2c25ce9833 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 09:01:51 +0000 Subject: [PATCH 24/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 542a9e9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e503a5eb6696af62188d01d29ecdf9af02b2b0d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 09:02:47 +0000 Subject: [PATCH 25/99] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 43 files changed, 6208 insertions(+), 4842 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 52bfcaf..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 7ae60fe..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a35f741 --- /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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 432a101..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-float64array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ed737df --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 6665c28555eaa8d72d1d1460e240e97427605600 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 10:54:48 +0000 Subject: [PATCH 26/99] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 329b593..30e7db0 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ limitations under the License. ## Usage ```javascript -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +161,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 2a24d61683e2bdabde8f38af8fb327732beb9364 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 10:54:49 +0000 Subject: [PATCH 27/99] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 30e7db0..bc61796 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ limitations under the License. ## Usage +```javascript +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@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/array-base-flatten2d-by/tags). For example, + ```javascript import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; ``` @@ -50,7 +55,7 @@ import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatte You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +166,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.1.0-esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From d9016f03b74b8db1e803c333a6ad2e3498508db4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 14:19:46 +0000 Subject: [PATCH 28/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0036788..d163ea9 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 0d41a5420df630ac88349888af122a357da29bb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 22:34:30 +0000 Subject: [PATCH 29/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a35f741..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@esm/index.mjs";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;iHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ed737df..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0e4ec09d0db077e04c305b383fdc739d4c99039e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 22:35:19 +0000 Subject: [PATCH 30/99] 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 | 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 | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 40 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 6208 insertions(+), 4941 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 d5c85b7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T04:22:32.505Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 7bed6e7..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eab9d99 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index d163ea9..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-float64array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3a41c2c --- /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 422976d..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From a59b8c11b64124209cd0246f04e89b006b4181ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 17:44:45 +0000 Subject: [PATCH 31/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 368fb31..038cc91 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From cd5c18d10db199b9463280f641559ac5dbc98dbe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:41:14 +0000 Subject: [PATCH 32/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eab9d99..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3a41c2c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ed3b6ceba116c8323f3465059e204c50a7a4a662 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:42:05 +0000 Subject: [PATCH 33/99] 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 | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 40 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 44 files changed, 6208 insertions(+), 4940 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 7bed6e7..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eab9d99 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 038cc91..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3f6a7a1 --- /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 422976d..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 522aa255b7c5de5089e36060ece49cdde0fff3f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 15:19:38 +0000 Subject: [PATCH 34/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 90bb515..4bc0fb3 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d3565a1963feff089689b25a583a7c2da9972bf5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:49:27 +0000 Subject: [PATCH 35/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eab9d99..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3f6a7a1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2b32fd1d695b2d27d8fc0fce77c7132f39b52373 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:50:05 +0000 Subject: [PATCH 36/99] 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 | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 6208 insertions(+), 4942 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 6f57a6a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T04:37:48.421Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 7bed6e7..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eab9d99 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 4bc0fb3..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ade061e --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 6dc955e36a4f9de6b3e97c2beb11e678b10002e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 11:41:34 +0000 Subject: [PATCH 37/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2d12df1..7a28c6b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 085b04d928249b722c2f6065096e5abd0350a50c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:43:52 +0000 Subject: [PATCH 38/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eab9d99..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ade061e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7616f5a45741da4c1e77fa2d5d7ad85668b244e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:44:29 +0000 Subject: [PATCH 39/99] 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 | 45 +- benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 6208 insertions(+), 4937 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 f07b046..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T04:49:30.316Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 7bed6e7..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 24eb7c1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eab9d99 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7a28c6b..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..04c7d19 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From f77e77f94078465d25170c8512644e8344654501 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 06:56:28 +0000 Subject: [PATCH 40/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c82d136..a5b2ae5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 92f099b0669573d15abce9206b5bb621c9a53fbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:42:55 +0000 Subject: [PATCH 41/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eab9d99..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 04c7d19..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7cbb40872f63c536f6a12e7b12b525559391031a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:43:10 +0000 Subject: [PATCH 42/99] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 6208 insertions(+), 4943 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 504fd29..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T04:16:06.185Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 12ca2c1..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2fd618f..72c53d6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61b0b07 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index a5b2ae5..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b6ad6e1 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 6e5a2bdbe6c0ab9a0df3b5a3c15fd9a4666edb13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jan 2024 22:10:46 +0000 Subject: [PATCH 43/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c82d136..a5b2ae5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 99adda34474b47ff6fa108234f03fc3d4fc66d47 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jan 2024 22:17:02 +0000 Subject: [PATCH 44/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 72c53d6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( `@stdlib/array/float64` ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61b0b07..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b6ad6e1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f695914375d8cfaa950978086aae04126649f10 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jan 2024 22:17:20 +0000 Subject: [PATCH 45/99] 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 | 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 6208 insertions(+), 4942 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 12ca2c1..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA 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 + + ```
@@ -229,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a0c3a..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/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/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 fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61b0b07 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index a5b2ae5..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7cc116d --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 9146946db6fc05e1f537c2e683b17c175590a4ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 07:26:35 +0000 Subject: [PATCH 46/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c82d136..a5b2ae5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d898e6ae3bc4b852005439141b806779dd36005b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 12:59:24 +0000 Subject: [PATCH 47/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61b0b07..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7cc116d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4ef65d21874a72ffbb90dfd82f5663804c4ba068 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 12:59:38 +0000 Subject: [PATCH 48/99] 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 | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 6208 insertions(+), 4948 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 5dfe0d0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:05:36.892Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 12ca2c1..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61b0b07 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index a5b2ae5..026cb00 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.1.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a51aa1e --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 5522d799794d4f2c98674d8cb0e27ff9d07817db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 14:14:49 +0000 Subject: [PATCH 49/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 705c89a..ad5c174 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0" }, "devDependencies": { "@stdlib/array-base-filled": "^0.1.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 50d4437532c87c152f2fc9d1eecc9ea44faecdfb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:11:54 +0000 Subject: [PATCH 50/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61b0b07..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a51aa1e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30d037f709db4a4b6cd8e91153f54f90b6b2ef05 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:12:16 +0000 Subject: [PATCH 51/99] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 6208 insertions(+), 4951 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 67e7add..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61b0b07 --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index ad5c174..84276c8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-float64array": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/utils-nary-function": "^0.2.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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..da32bf7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From ad993c1856864f640262ddb56604b0f4ba60eb8f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 22:12:03 +0000 Subject: [PATCH 52/99] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa437b8..d097388 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ limitations under the License. ## Usage ```javascript -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +161,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From c9f447a4c22ebd564c674a4f5597041eec4ed9ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 22:12:03 +0000 Subject: [PATCH 53/99] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d097388..c5498c5 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ limitations under the License. ## Usage +```javascript +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@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/array-base-flatten2d-by/tags). For example, + ```javascript import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; ``` @@ -50,7 +55,7 @@ import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatte You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +166,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.0-esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 3b6e0533164979747b6b9f58e8db84c38140b33f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 00:24:49 +0000 Subject: [PATCH 54/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3f5d138..3fde5d5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.0", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From b94b1e0459969bada172b9ed3dd6e66160a751a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 05:50:16 +0000 Subject: [PATCH 55/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6376 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61b0b07..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index da32bf7..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 174a0dd27a605a0e224a589c0433ab8af7437779 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 05:50:33 +0000 Subject: [PATCH 56/99] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 4873 insertions(+), 4945 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 3fde5d5..df5fd77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.0", - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-float64array": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.0", - "@stdlib/utils-nary-function": "^0.2.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From a273a8b8def94d9a8c0e461c2e979233b01da0fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 07:26:57 +0000 Subject: [PATCH 57/99] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a2cb1b..e6f500e 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ limitations under the License. ## Usage ```javascript -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +161,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 1b573944136e780b7f56f71180a606ebd863d518 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 07:26:58 +0000 Subject: [PATCH 58/99] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6f500e..150ef00 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ limitations under the License. ## Usage +```javascript +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@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/array-base-flatten2d-by/tags). For example, + ```javascript import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; ``` @@ -50,7 +55,7 @@ import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatte You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +166,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.1-esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 3acaed1dd5e6ded24d4f7801c5dcf9faef5584a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 06:49:03 +0000 Subject: [PATCH 59/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c7a202f..1491a95 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.1", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1891e1393e2640cfa1e9126412c869301e0dd902 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 12:15:50 +0000 Subject: [PATCH 60/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2362bf72b18ee53e57f7ea2fe61c044508c69b5d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 12:16:06 +0000 Subject: [PATCH 61/99] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 4947 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 3b62d49..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T04:52:11.024Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 1491a95..df5fd77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-float64array": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 5e1f624d759cecf76c753accac68026b770eb187 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 06:04:59 +0000 Subject: [PATCH 62/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c7a202f..1491a95 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.1", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 8b618f096ebb9055ca56df848bc0e958e0c678a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:14:49 +0000 Subject: [PATCH 63/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a4d3bf52e9206fb28c6cfa50bbde3eb8cc8c902f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:14:59 +0000 Subject: [PATCH 64/99] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 4950 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 14f0143..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:07:14.186Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 1491a95..df5fd77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-float64array": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 16a23cacde166d8c75dd660a0e414cfe1fd333dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 02:28:38 +0000 Subject: [PATCH 65/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c7a202f..1491a95 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.1", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1f1ba6eed2310f9b5666e2bce6f07f7c9831dded Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:55:23 +0000 Subject: [PATCH 66/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1ff0b7cffeea187b4e5237d362beded44c09f823 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:55:40 +0000 Subject: [PATCH 67/99] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 4873 insertions(+), 4951 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 1491a95..df5fd77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-float64array": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "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", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 8ebc1b28690411e0907635d6939a24d5fe8c010f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:23:35 +0000 Subject: [PATCH 68/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7a0ff35..6dbe772 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.1", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From bd9ed2767af6f3a424e0b54d52ca842b1cc1a885 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:41:14 +0000 Subject: [PATCH 69/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d916ee187b400c94a1152301b399de78087e89e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:41:26 +0000 Subject: [PATCH 70/99] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 4873 insertions(+), 5108 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 6dbe772..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From a834fd64c3c457f179198103c5968f8fd8d26916 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:50:24 +0000 Subject: [PATCH 71/99] Update README.md for ESM bundle v0.2.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a378b3..d32f98d 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ limitations under the License. ## Usage ```javascript -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +161,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 992cacb41b5938ed8e1e90a06e33ab73f7a3c7dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:50:24 +0000 Subject: [PATCH 72/99] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d32f98d..f93fa78 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ limitations under the License. ## Usage +```javascript +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@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/array-base-flatten2d-by/tags). For example, + ```javascript import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; ``` @@ -50,7 +55,7 @@ import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatte You can also import the following named exports from the package: ```javascript -import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; +import { assign } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; ``` #### flatten2dBy( x, shape, colexicographic, clbk\[, thisArg] ) @@ -161,7 +166,7 @@ y = flatten2dBy.assign( x, [ 2, 2 ], true, out, 1, 0, scale ); import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; -import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@v0.2.2-esm/index.mjs'; +import flatten2dBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten2d-by@esm/index.mjs'; var fcn = naryFunction( abs, 1 ); From 1ea89531777bb28323d5ae012e50cc314e3a04bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 06:55:30 +0000 Subject: [PATCH 73/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b4f7f2a..7e9f444 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 790236dd785a767569bb826ba9414400d936251c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 11:35:40 +0000 Subject: [PATCH 74/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 36c3f8e86db9f1c9442e083c11f613622472c1bd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 11:35:52 +0000 Subject: [PATCH 75/99] 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 | 88 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 5048 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 81789fa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T04:58:44.726Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7e9f444..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From e5b8d33df79909967a3b52f18bd9f55f9fe54e96 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:07:39 +0000 Subject: [PATCH 76/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b4f7f2a..7e9f444 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c146ab1552a4896abfd9897d3444f3439a0c0aad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:21:35 +0000 Subject: [PATCH 77/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 68638064fa75431cc7308e5daf3ef0c92ec4bce0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:21:51 +0000 Subject: [PATCH 78/99] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 5111 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 e0898fc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T20:27:02.189Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7e9f444..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 0f2431eea3d00de6bbb9f3554bd1c850d947aa86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 07:14:28 +0000 Subject: [PATCH 79/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 307d94f..7ac1fe5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 02ccba19f4e288a7ab078097f4bdef4db414817d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:32:21 +0000 Subject: [PATCH 80/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9a9fad6d25df8d3fe108451be7e43b8056e62b7b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:32:35 +0000 Subject: [PATCH 81/99] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 5111 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 a20ce98..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T05:18:39.826Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f31305d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param v - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7ac1fe5..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 6d23b121779368880f332a41d60b4b90249f8a36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:15:50 +0000 Subject: [PATCH 82/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 307d94f..7ac1fe5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From dac15d6206e20e3ea8c7f2edbd559ec3330fc990 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:19:41 +0000 Subject: [PATCH 83/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d74df8534923879c024b2509f33ea2254a10d6c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:19:55 +0000 Subject: [PATCH 84/99] 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 | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 185 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 45 files changed, 4873 insertions(+), 5144 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7ac1fe5..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 7e98c61407dddddbc7a2bc01a91730113f62b996 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 07:30:04 +0000 Subject: [PATCH 85/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 307d94f..7ac1fe5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 95c408041234433a8dff14fb0f20abfa9dd85e27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 12:10:56 +0000 Subject: [PATCH 86/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ed80bf8d31fb6e47638bda68115cdd4f7f41431e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 12:11:10 +0000 Subject: [PATCH 87/99] 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 | 185 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 5145 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 37649c8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T05:30:27.149Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7ac1fe5..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 2f7fc078ffb52c0c158a3f5f270f5ca852f06fe5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 07:22:43 +0000 Subject: [PATCH 88/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 307d94f..7ac1fe5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 2033c5a33731c857392e5c5334f0e3ab376805f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:22:01 +0000 Subject: [PATCH 89/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6d6f8c59f5343dad5bd0e3dd81881af4a84b803e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:22:16 +0000 Subject: [PATCH 90/99] 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 | 185 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4873 insertions(+), 5145 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 1c14559..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T05:34:22.506Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 7ac1fe5..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From 32b8628ababf22eb1ed72a18d1a746a8a588cdbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 07:38:26 +0000 Subject: [PATCH 91/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 775cbb7..28c31d1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c29b1b207425ea5f0087ccf8ef82ac58af2782e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:31:48 +0000 Subject: [PATCH 92/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 133cd6f4f14e6e8945c71b7453d01b930aadd9a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:32:00 +0000 Subject: [PATCH 93/99] 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 | 185 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 47 files changed, 4873 insertions(+), 5250 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 bdb85d5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T05:42:55.782Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -231,7 +228,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. 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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 28c31d1..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From bbe0643a79df2dbca021b6cf2e355681ec81dfce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 15 Dec 2024 03:42:11 +0000 Subject: [PATCH 94/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 775cbb7..28c31d1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 22fd3caca3e777e84ca2819d122c2a466b5f2a54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 15 Dec 2024 03:54:06 +0000 Subject: [PATCH 95/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f8fb59e050c5d60c292e6e041970d5dea97b673f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 15 Dec 2024 03:54:23 +0000 Subject: [PATCH 96/99] 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 | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 46 files changed, 4874 insertions(+), 5251 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -237,7 +234,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. @@ -302,7 +299,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/base/flatten2d]: https://github.com/stdlib-js/array-base-flatten2d +[@stdlib/array/base/flatten2d]: https://github.com/stdlib-js/array-base-flatten2d/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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 28c31d1..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); From c8cbc75da0f151df9ab993732ced5043236b4f64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:18:37 +0000 Subject: [PATCH 97/99] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 775cbb7..28c31d1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-filled": "^0.2.2", @@ -92,4 +93,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From b654a0e8d90b579c446027a2bdd6b60f90b2f89b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:56:45 +0000 Subject: [PATCH 98/99] Remove files --- index.d.ts | 194 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5041 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 405a42f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,194 +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 { Collection, Array2D } from '@stdlib/types/array'; -import { Shape2D } from '@stdlib/types/ndarray'; - -/** -* Nullary callback function. -* -* @returns result -*/ -type Nullary = ( this: V ) => U; - -/** -* Unary callback function. -* -* @param value - array element -* @returns result -*/ -type Unary = ( this: V, value: T ) => U; - -/** -* Binary callback function. -* -* @param value - array element -* @param indices - element indices -* @returns result -*/ -type Binary = ( this: V, value: T, indices: Array ) => U; - -/** -* Ternary callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; - -/** -* Callback function. -* -* @param value - array element -* @param indices - element indices -* @param arr - input array -* @returns result -*/ -type Callback = Nullary | Unary | Binary | Ternary; - -/** -* Interface describing `flatten2dBy`. -*/ -interface Flatten2dBy { - /** - * Flattens a two-dimensional nested array according to a callback function. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns flattened array - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - ( x: Array2D, shape: Shape2D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; - - - /** - * Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. - * - * ## Notes - * - * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). - * - * @param x - input array - * @param shape - array shape - * @param colexicographic - specifies whether to flatten array values in colexicographic order - * @param out - output array - * @param stride - output array stride - * @param offset - output array index offset - * @param clbk - callback function - * @param thisArg - callback execution context - * @returns output array - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 4, 6, 8 ] - * - * @example - * var Float64Array = require( '@stdlib/array-float64' ); - * - * function scale( v ) { - * return v * 2; - * } - * - * var x = [ [ 1, 2 ], [ 3, 4 ] ]; - * - * var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); - * // returns [ 2, 6, 4, 8 ] - */ - assign( x: Array2D, shape: Shape2D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; -} - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param x - input array -* @param shape - array shape -* @param colexicographic - specifies whether to flatten array values in colexicographic order -* @param clbk - callback function -* @param thisArg - callback execution context -* @returns flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -declare var flatten2dBy: Flatten2dBy; - - -// EXPORTS // - -export = flatten2dBy; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 32aadcc..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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 597e1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 80406fb09a06f2549a349ff4146ab9b998ed3d27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:57:20 +0000 Subject: [PATCH 99/99] 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 | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 143 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 106 - docs/types/test.ts | 340 -- examples/index.js | 72 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/assign.js | 100 - lib/index.js | 82 - lib/main.js | 93 - package.json | 63 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 393 -- test/test.js | 40 - test/test.main.js | 218 - 47 files changed, 4874 insertions(+), 5252 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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/assign.js 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.assign.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 0d5d23b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:08:19.949Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94022e5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 43bada2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a52f914..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 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
@@ -237,7 +234,7 @@ out = flatten2dBy( x, [ 4, 4 ], true, fcn ); ## 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]. @@ -302,7 +299,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/base/flatten2d]: https://github.com/stdlib-js/array-base-flatten2d +[@stdlib/array/base/flatten2d]: https://github.com/stdlib-js/array-base-flatten2d/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 a054e0d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,143 +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 isArray = require( '@stdlib/assert-is-array' ); -var isFloat64Array = require( '@stdlib/assert-is-float64array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var filled = require( '@stdlib/array-base-filled' ); -var Float64Array = require( '@stdlib/array-float64' ); -var pkg = require( './../package.json' ).name; -var flatten2dBy = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Scales an input value. -* -* @private -* @param {number} v - input value -* @returns {number} output value -* -* @example -* var v = scale( 2.0 ); -* // returns 4.0 -*/ -function scale( v ) { - return v * 2.0; -} - - -// MAIN // - -bench( pkg+':size=100,lexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], false, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':size=100,colexicographic', function benchmark( b ) { - var x; - var i; - var v; - - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy( x, [ 10, 10 ], true, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,lexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], false, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign:size=100,colexicographic', function benchmark( b ) { - var out; - var x; - var i; - var v; - - out = new Float64Array( 100 ); - x = filled( zeroTo( 10 ), 10 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = flatten2dBy.assign( x, [ 10, 10 ], true, out, 1, 0, scale ); - if ( typeof v !== 'object' ) { - b.fail( 'should return a Float64Array' ); - } - } - b.toc(); - if ( !isFloat64Array( v ) ) { - b.fail( 'should return a Float64Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bebe5f7..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by" -%% click B href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/flatten2d-by -[production-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-flatten2d-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-flatten2d-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fcb718d..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import flatten2dBy from '../docs/types/index'; -export = flatten2dBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec52113..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var y=p(function(z,q){ -function O(i,t,c,f,s){var n,o,u,r,a,e;if(o=t[1],u=t[0],n=[],c){for(r=0;r} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' );\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwDA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EAGdI,EAAM,CAAC,EAGFH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAI,KAAMF,EAAK,KAAMC,EAASJ,EAAGS,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG/D,OAAOK,CACR,CACA,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAI,KAAMF,EAAK,KAAMC,EAASM,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGR,CAAE,CAAE,EAG1D,OAAOK,CACR,CAKAP,EAAO,QAAUC,IC5FjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,SAASC,EAAaC,EAAGC,EAAOC,EAAiBC,EAAKC,EAAQC,EAAQC,EAAMC,EAAU,CACrF,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAL,EAAKP,EAAO,CAAE,EACdQ,EAAKR,EAAO,CAAE,EAGdY,EAAKR,EACAH,EAAkB,CACtB,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBR,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASP,EAAGW,CAAG,EAAGD,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EAC7Da,GAAMT,EAGR,OAAOD,CACR,CACA,IAAMQ,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKZ,EAAGW,CAAG,EACLD,EAAK,EAAGA,EAAKF,EAAIE,IACtBP,EAAKU,CAAG,EAAIP,EAAK,KAAMC,EAASK,EAAIF,CAAG,EAAG,CAAEC,EAAID,CAAG,EAAGV,CAAE,EACxDa,GAAMT,EAGR,OAAOD,CACR,CAKAL,EAAO,QAAUC,IC9BjB,IAAIe,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD", - "names": ["require_main", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "clbk", "thisArg", "out", "S0", "S1", "i0", "i1", "a0", "require_assign", "__commonJSMin", "exports", "module", "flatten2dBy", "x", "shape", "colexicographic", "out", "stride", "offset", "clbk", "thisArg", "S0", "S1", "i0", "i1", "a0", "io", "setReadOnly", "main", "assign"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a46014b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,106 +0,0 @@ - -{{alias}}( x, shape, colex, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Flattened array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = {{alias}}( x, [ 2, 2 ], false, fcn ) - [ 2, 4, 6, 8 ] - > out = {{alias}}( x, [ 2, 2 ], true, fcn ) - [ 2, 6, 4, 8 ] - - -{{alias}}.assign( x, shape, colex, out, stride, offset, clbk[, thisArg] ) - Flattens a two-dimensional nested array according to a callback function - and assigns elements to a provided output array. - - The function assumes that all nested arrays have the same length (i.e., the - input array is *not* a ragged array). - - The callback function is provided the following arguments: - - - value: nested array element. - - indices: element indices (in lexicographic order). - - arr: the input array. - - Parameters - ---------- - x: Array - Input array. - - shape: Array - Array shape. - - colex: boolean - Specifies whether to flatten array values in colexicographic order. - - out: Collection - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array index offset. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - > function fcn( v ) { return v * 2; }; - > var x = [ [ 1, 2 ], [ 3, 4 ] ]; - > var out = [ 0, 0, 0, 0 ]; - > var v = {{alias}}.assign( x, [ 2, 2 ], false, out, 1, 0, fcn ) - [ 2, 4, 6, 8 ] - > var bool = ( v === out ) - true - > out = [ 0, 0, 0, 0 ]; - > {{alias}}.assign( x, [ 2, 2 ], true, out, 1, 0, fcn ); - > out - [ 2, 6, 4, 8 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1d4e2b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,340 +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 flatten2dBy = require( './index' ); - -/** -* Identity function. -* -* @param value - input value -* @returns input value -*/ -function identity( value: T ): T { - return value; -} - - -// TESTS // - -// The function returns an array... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, identity ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity ); // $ExpectType number[] - - flatten2dBy( x, [ 2, 2 ], false, identity, {} ); // $ExpectType number[] - flatten2dBy( x, [ 2, 2 ], true, identity, {} ); // $ExpectType number[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity ); // $ExpectType string[] - - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, identity, {} ); // $ExpectType string[] - flatten2dBy( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, identity, {} ); // $ExpectType string[] -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - flatten2dBy( 1, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity ); // $ExpectError - - flatten2dBy( 1, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( true, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( false, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( null, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( void 0, [ 2, 2 ], false, identity, {} ); // $ExpectError - flatten2dBy( {}, [ 2, 2 ], false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, '', false, identity ); // $ExpectError - flatten2dBy( x, 1, false, identity ); // $ExpectError - flatten2dBy( x, true, false, identity ); // $ExpectError - flatten2dBy( x, false, false, identity ); // $ExpectError - flatten2dBy( x, null, false, identity ); // $ExpectError - flatten2dBy( x, void 0, false, identity ); // $ExpectError - flatten2dBy( x, {}, false, identity ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity ); // $ExpectError - - flatten2dBy( x, '', false, identity, {} ); // $ExpectError - flatten2dBy( x, 1, false, identity, {} ); // $ExpectError - flatten2dBy( x, true, false, identity, {} ); // $ExpectError - flatten2dBy( x, false, false, identity, {} ); // $ExpectError - flatten2dBy( x, null, false, identity, {} ); // $ExpectError - flatten2dBy( x, void 0, false, identity, {} ); // $ExpectError - flatten2dBy( x, {}, false, identity, {} ); // $ExpectError - flatten2dBy( x, [ 1, '2', 3 ], false, identity, {} ); // $ExpectError - flatten2dBy( x, ( x: number ): number => x, false, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], '', identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], '', identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], 1, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], null, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], void 0, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], {}, identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], [], identity, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy( x, [ 2, 2 ], false, '' ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0 ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [] ); // $ExpectError - - flatten2dBy( x, [ 2, 2 ], false, '', {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, 1, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, true, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, false, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, null, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, void 0, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, {}, {} ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy(); // $ExpectError - flatten2dBy( x ); // $ExpectError - flatten2dBy( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy( x, [ 2, 2 ], false, identity, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns a collection... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - const out1 = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( x, [ 2, 2 ], false, out1, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( x, [ 2, 2 ], true, out1, 1, 0, identity, {} ); // $ExpectType Collection - - const out2 = [ '', '', '', '' ]; - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity ); // $ExpectType Collection - - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], false, out2, 1, 0, identity, {} ); // $ExpectType Collection - flatten2dBy.assign( [ [ '1', '2' ], [ '3', '4' ] ], [ 2, 2 ], true, out2, 1, 0, identity, {} ); // $ExpectType Collection -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... -{ - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( 1, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( true, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( false, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( null, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( void 0, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( {}, [ 2, 2 ], false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object containing numbers... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, '', false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, '', false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, 1, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, true, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, false, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, null, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, void 0, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, {}, false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 1, '2', 3 ], false, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, ( x: number ): number => x, false, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a boolean... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], '', out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], 1, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], null, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], void 0, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], {}, out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], [], out, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], ( x: number ): number => x, out, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, 1, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, true, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, false, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, null, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, void 0, 1, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, {}, 1, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, '1', 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, true, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, false, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, null, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, void 0, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, {}, 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, [], 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, ( x: number ): number => x, 0, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, '1', identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, true, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, false, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, null, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, void 0, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, {}, identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, [], identity, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, ( x: number ): number => x, identity, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a seventh argument which is not a function... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1' ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [] ); // $ExpectError - - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, '1', {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, 1, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, true, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, false, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, null, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, void 0, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, {}, {} ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, [], {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const x = [ [ 1, 2 ], [ 3, 4 ] ]; - const out = [ 0, 0, 0, 0 ]; - - flatten2dBy.assign(); // $ExpectError - flatten2dBy.assign( x ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ] ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0 ); // $ExpectError - flatten2dBy.assign( x, [ 2, 2 ], false, out, 1, 0, identity, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ef9daef..0000000 --- a/examples/index.js +++ /dev/null @@ -1,72 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib' ); - -var fcn = naryFunction( abs, 1 ); - -var x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] -]; - -var out = flatten2dBy( x, [ 0, 0 ], false, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 0, 0 ], true, fcn ); -console.log( out ); -// => [] - -out = flatten2dBy( x, [ 1, 1 ], false, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 1, 1 ], true, fcn ); -console.log( out ); -// => [ 1 ] - -out = flatten2dBy( x, [ 2, 2 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 5, 6 ] - -out = flatten2dBy( x, [ 2, 2 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 2, 6 ] - -out = flatten2dBy( x, [ 3, 3 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] - -out = flatten2dBy( x, [ 3, 3 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] - -out = flatten2dBy( x, [ 4, 4 ], false, fcn ); -console.log( out ); -// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] - -out = flatten2dBy( x, [ 4, 4 ], true, fcn ); -console.log( out ); -// => [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0021add..405a42f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Array2D } from '@stdlib/types/array'; import { Shape2D } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..32aadcc --- /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";function n(r,n,e,o,f){var s,t,l,a,i,u;if(t=n[1],l=n[0],s=[],e){for(a=0;a} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Array} flattened array\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, clbk, thisArg ) {\n\tvar out;\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Initialize an output array:\n\tout = [];\n\n\t// Iterate over the array dimensions...\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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// MAIN //\n\n/**\n* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array.\n*\n* ## Notes\n*\n* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).\n*\n* @param {Array} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array index offset\n* @param {Function} clbk - callback function\n* @param {*} [thisArg] - callback execution context\n* @returns {Collection} output array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*/\nfunction flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len\n\tvar S0;\n\tvar S1;\n\tvar i0;\n\tvar i1;\n\tvar a0;\n\tvar io;\n\n\t// Extract loop variables:\n\tS0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices\n\tS1 = shape[ 0 ];\n\n\t// Iterate over the array dimensions...\n\tio = offset;\n\tif ( colexicographic ) {\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\tout[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order\n\t\t\t\tio += stride;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\ta0 = x[ i1 ];\n\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\tout[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default flatten2dBy;\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* Flatten a two-dimensional nested array according to a callback function.\n*\n* @module @stdlib/array-base-flatten2d-by\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], false, scale );\n* // returns [ 2, 4, 6, 8 ]\n*\n* @example\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = flatten2dBy( x, [ 2, 2 ], true, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import flatten2dBy from '@stdlib/array-base-flatten2d-by';\n*\n* function scale( v ) {\n* return v * 2;\n* }\n*\n* var x = [ [ 1, 2 ], [ 3, 4 ] ];\n*\n* var out = new Float64Array( 4 );\n* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale );\n* // returns [ 2, 6, 4, 8 ]\n*\n* var bool = ( y === out );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport assign from './assign.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["flatten2dBy","x","shape","colexicographic","clbk","thisArg","out","S0","S1","i0","i1","a0","push","call","stride","offset","io","setReadOnly","main","assign"],"mappings":";;wHAwDA,SAASA,EAAaC,EAAGC,EAAOC,EAAiBC,EAAMC,GACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,GAPAJ,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZI,EAAM,GAGDH,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAIM,KAAMR,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,IAG3D,OAAOK,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAIM,KAAMR,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,IAGtD,OAAOK,CACR,CCxBA,SAASN,EAAaC,EAAGC,EAAOC,EAAiBG,EAAKQ,EAAQC,EAAQX,EAAMC,GAC3E,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAK,EAQJ,GALAT,EAAKL,EAAO,GACZM,EAAKN,EAAO,GAGZc,EAAKD,EACAZ,EAAkB,CACtB,IAAMM,EAAK,EAAGA,EAAKF,EAAIE,IACtB,IAAMC,EAAK,EAAGA,EAAKF,EAAIE,IACtBJ,EAAKU,GAAOZ,EAAKS,KAAMR,EAASJ,EAAGS,GAAMD,GAAM,CAAEC,EAAID,GAAMR,GAC3De,GAAMF,EAGR,OAAOR,CACP,CACD,IAAMI,EAAK,EAAGA,EAAKF,EAAIE,IAEtB,IADAC,EAAKV,EAAGS,GACFD,EAAK,EAAGA,EAAKF,EAAIE,IACtBH,EAAKU,GAAOZ,EAAKS,KAAMR,EAASM,EAAIF,GAAM,CAAEC,EAAID,GAAMR,GACtDe,GAAMF,EAGR,OAAOR,CACR,CClBAW,EAAAC,EAAA,SAAAC"} \ No newline at end of file diff --git a/lib/assign.js b/lib/assign.js deleted file mode 100644 index 2907449..0000000 --- a/lib/assign.js +++ /dev/null @@ -1,100 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function and assigns elements to a provided output array. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Collection} out - output array -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array index offset -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) { // eslint-disable-line max-len - var S0; - var S1; - var i0; - var i1; - var a0; - var io; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Iterate over the array dimensions... - io = offset; - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ); // equivalent to storing in column-major (Fortran-style) order - io += stride; - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ); // equivalent to storing in row-major (C-style) order - io += stride; - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a99853f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,82 +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'; - -/** -* Flatten a two-dimensional nested array according to a callback function. -* -* @module @stdlib/array-base-flatten2d-by -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var flatten2dBy = require( '@stdlib/array-base-flatten2d-by' ); -* -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = new Float64Array( 4 ); -* var y = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, scale ); -* // returns [ 2, 6, 4, 8 ] -* -* var bool = ( y === out ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var assign = require( './assign.js' ); - - -// MAIN // - -setReadOnly( main, 'assign', assign ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 044ba56..0000000 --- a/lib/main.js +++ /dev/null @@ -1,93 +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'; - -// MAIN // - -/** -* Flattens a two-dimensional nested array according to a callback function. -* -* ## Notes -* -* - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). -* -* @param {Array} x - input nested array -* @param {NonNegativeIntegerArray} shape - array shape -* @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order -* @param {Function} clbk - callback function -* @param {*} [thisArg] - callback execution context -* @returns {Array} flattened array -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], false, scale ); -* // returns [ 2, 4, 6, 8 ] -* -* @example -* function scale( v ) { -* return v * 2; -* } -* -* var x = [ [ 1, 2 ], [ 3, 4 ] ]; -* -* var out = flatten2dBy( x, [ 2, 2 ], true, scale ); -* // returns [ 2, 6, 4, 8 ] -*/ -function flatten2dBy( x, shape, colexicographic, clbk, thisArg ) { - var out; - var S0; - var S1; - var i0; - var i1; - var a0; - - // Extract loop variables: - S0 = shape[ 1 ]; // for nested arrays, the last dimensions have the fastest changing indices - S1 = shape[ 0 ]; - - // Initialize an output array: - out = []; - - // Iterate over the array dimensions... - if ( colexicographic ) { - for ( i0 = 0; i0 < S0; i0++ ) { - for ( i1 = 0; i1 < S1; i1++ ) { - out.push( clbk.call( thisArg, x[ i1 ][ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in column-major (Fortran-style) order - } - } - return out; - } - for ( i1 = 0; i1 < S1; i1++ ) { - a0 = x[ i1 ]; - for ( i0 = 0; i0 < S0; i0++ ) { - out.push( clbk.call( thisArg, a0[ i0 ], [ i1, i0 ], x ) ); // equivalent to storing in row-major (C-style) order - } - } - return out; -} - - -// EXPORTS // - -module.exports = flatten2dBy; diff --git a/package.json b/package.json index 28c31d1..9587151 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Flatten a two-dimensional nested array according to a callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-filled": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-float64array": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/utils-nary-function": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -93,4 +36,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..597e1b7 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 6c0c608..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,393 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var flatten2dBy = require( './../lib/assign.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 5, 6, 9, 10, 13, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], false, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 0, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [] ); - out = new Float64Array( 0 ); - actual = flatten2dBy( x, [ 1, 0 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1 ] ); - out = new Float64Array( 1 ); - actual = flatten2dBy( x, [ 1, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 2 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 1, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5 ] ); - out = new Float64Array( 2 ); - actual = flatten2dBy( x, [ 2, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 2, 6, 3, 7 ] ); - out = new Float64Array( 6 ); - actual = flatten2dBy( x, [ 2, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ] ); - out = new Float64Array( 9 ); - actual = flatten2dBy( x, [ 3, 3 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13 ] ); - out = new Float64Array( 4 ); - actual = flatten2dBy( x, [ 4, 1 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 4, 2 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ] ); // eslint-disable-line max-len - out = new Float64Array( 16 ); - actual = flatten2dBy( x, [ 4, 4 ], true, out, 1, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 2, 0, 3, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing a stride (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 1, 0, 3, 0, 2, 0, 4, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 2, 0, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 2, 3, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing an offset (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 0, 1, 3, 2, 4, 0, 0 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, 1, 2, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (lexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 3, 0, 2, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], false, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (colexicographic)', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ - [ -1, -2 ], - [ -3, -4 ] - ]; - - expected = new Float64Array( [ 0, 4, 0, 2, 0, 3, 0, 1 ] ); - out = new Float64Array( 8 ); - actual = flatten2dBy( x, [ 2, 2 ], true, out, -2, 7, clbk ); - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], false, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var out; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - out = new Float64Array( 4 ); - flatten2dBy( x, [ 2, 2 ], true, out, 1, 0, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6234f4f..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var flatten2dBy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( hasOwnProp( flatten2dBy, 'assign' ), true, 'has property' ); - t.strictEqual( typeof flatten2dBy.assign, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a99f230..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,218 +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 naryFunction = require( '@stdlib/utils-nary-function' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var flatten2dBy = require( './../lib/main.js' ); - - -// VARIABLES // - -var clbk = naryFunction( abs, 1 ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof flatten2dBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function flattens a nested array (lexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 5, 6, 7, 9, 10, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 5, 6, 9, 10, 13, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], false, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function flattens a nested array (colexicographic)', function test( t ) { - var expected; - var actual; - var x; - - x = [ - [ -1, -2, -3, -4 ], - [ -5, -6, -7, -8 ], - [ -9, -10, -11, -12 ], - [ -13, -14, -15, -16 ] - ]; - - expected = []; - actual = flatten2dBy( x, [ 0, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 0, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = []; - actual = flatten2dBy( x, [ 1, 0 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1 ]; - actual = flatten2dBy( x, [ 1, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = flatten2dBy( x, [ 1, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5 ]; - actual = flatten2dBy( x, [ 2, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6 ]; - actual = flatten2dBy( x, [ 2, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 2, 6, 3, 7 ]; - actual = flatten2dBy( x, [ 2, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 2, 6, 10, 3, 7, 11 ]; - actual = flatten2dBy( x, [ 3, 3 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13 ]; - actual = flatten2dBy( x, [ 4, 1 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14 ]; - actual = flatten2dBy( x, [ 4, 2 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ]; - actual = flatten2dBy( x, [ 4, 4 ], true, clbk ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports setting the callback execution context (lexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], false, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -}); - -tape( 'the function supports setting the callback execution context (colexicographic)', function test( t ) { - var ctx; - var x; - - x = [ - [ 1, 2 ], - [ 3, 4 ] - ]; - - ctx = { - 'count': 0 - }; - - flatten2dBy( x, [ 2, 2 ], true, fcn, ctx ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn( value, indices, arr ) { - this.count += 1; // eslint-disable-line no-invalid-this - t.strictEqual( indices.length, 2, 'returns expected value' ); - t.strictEqual( value, arr[ indices[0] ][ indices[1] ], 'returns expected value' ); - t.strictEqual( arr, x, 'returns expected value' ); - } -});