From c6bce03e81c5497d63b7b2f488d46607fb99894d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 03:35:05 +0000 Subject: [PATCH 01/70] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ceaa12..c339276 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 4acf0cc44ec27d2c3bf0987ab1cd7fd5232aeccd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 03:39:36 +0000 Subject: [PATCH 02/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 443 -- lib/validate.js | 66 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 87 - 56 files changed, 6213 insertions(+), 5282 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 670b71c..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 637d1f8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=o(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=o(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N -});var v=o(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=o(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=o(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=o(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,u,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(n=H(r),l=n(r,0),L(l))u="bool";else if(V(l))u="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else if(i==="int32")u="int";else if(i==="uint8")u="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:u,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cbaae39..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAK/B,GAJAD,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,UAE3ED,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICrZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d330d1f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType ArrayObject -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index ec227cf..95f951b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0ddc494 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4a7842e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index cb51518..0000000 --- a/lib/main.js +++ /dev/null @@ -1,443 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b617482..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index c339276..050e678 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Array index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-copy": "^0.1.0", - "@stdlib/array-base-resolve-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-linked-list": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.1.0", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a3edf28 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index adb0867..0000000 --- a/test/test.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); From 85cd84cc0356ba08eed0a75a3d3aaa0a36d8df2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 03:52:24 +0000 Subject: [PATCH 03/70] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ceaa12..c339276 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 015ca2b08eb7d815b01295803e5c58f3910fb4ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 03:52:47 +0000 Subject: [PATCH 04/70] Remove files --- index.d.ts | 539 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6721 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 95f951b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; - -/** -* Boolean index array. -*/ -type BooleanIndexArray = Collection | AccessorArrayLike; - -/** -* Integer index array. -*/ -type IntegerIndexArray = Collection | AccessorArrayLike; - -/** -* Index array. -*/ -type IndexArray = BooleanIndexArray | IntegerIndexArray; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing an object containing array index data. -*/ -interface BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IndexArray; - - /** - * The type of array index. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: DataType; -} - -/** -* Interface describing an object containing mask array data. -*/ -interface MaskArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Uint8Array; - - /** - * The type of array index. - */ - type: 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: 'uint8'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface Int32ArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Int32Array; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'int32'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface IntegerArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IntegerIndexArray; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Interface describing an object containing boolean array data. -*/ -interface BooleanArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: BooleanIndexArray; - - /** - * The type of array index. - */ - type: 'bool'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Array object data. -*/ -type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null; - -/** -* Interface describing an array index object. -*/ -interface BaseArrayIndex { - /** - * Read-only property returning the data associated with an `ArrayIndex` instance. - */ - data: IndexArray; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: DataType; - - /** - * Read-only property returning the unique identifier associated with an `ArrayIndex` instance. - */ - id: string; - - /** - * Boolean indicating if an `ArrayIndex` instance is actively cached. - */ - isCached: boolean; - - /** - * Read-only property returning the array index type. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * Serializes an `ArrayIndex` to a string. - * - * @returns serialized string - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * // returns - * - * var str = idx.toString(); - * // e.g., 'ArrayIndex<0>' - */ - toString(): string; -} - -/** -* Interface describing a mask array index object. -*/ -interface MaskArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'mask'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'uint8'; - - /** - * Read-only property returning the underlying array data. - */ - data: Uint8Array; -} - -/** -* Interface describing an integer array index object. -*/ -interface Int32ArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'int32'; - - /** - * Read-only property returning the underlying array data. - */ - data: Int32Array; -} - -/** -* Interface describing a boolean array index object. -*/ -interface BooleanArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'bool'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: BooleanIndexArray; -} - -/** -* Interface describing an integer array index object. -*/ -interface IntegerArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: IntegerIndexArray; -} - -/** -* Array index object. -*/ -type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex; - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): ArrayObject; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0ddc494..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4a7842e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a3edf28..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a5dc548b3cdf10709c75e58d505ea7ff5de3f3fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 03:53:20 +0000 Subject: [PATCH 05/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 443 -- lib/validate.js | 66 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 87 - 56 files changed, 6213 insertions(+), 5282 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 670b71c..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 637d1f8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=o(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=o(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N -});var v=o(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=o(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=o(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=o(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,u,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(n=H(r),l=n(r,0),L(l))u="bool";else if(V(l))u="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else if(i==="int32")u="int";else if(i==="uint8")u="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:u,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cbaae39..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAK/B,GAJAD,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,UAE3ED,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICrZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d330d1f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType ArrayObject -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c4d6613..09ce019 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0ddc494 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4a7842e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index cb51518..0000000 --- a/lib/main.js +++ /dev/null @@ -1,443 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b617482..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index c339276..050e678 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Array index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-copy": "^0.1.0", - "@stdlib/array-base-resolve-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-linked-list": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.1.0", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ba5c07c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index adb0867..0000000 --- a/test/test.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); From 094ade063c1e9dcea3a65a3f0873d5f7ab181031 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 14:16:25 +0000 Subject: [PATCH 06/70] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8364cc2..1ac745e 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 6ab96f2b68ea273b148ae18f0e9dffa3bdf37cb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 14:16:56 +0000 Subject: [PATCH 07/70] Remove files --- index.d.ts | 539 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6721 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 09ce019..0000000 --- a/index.d.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; - -/** -* Boolean index array. -*/ -type BooleanIndexArray = Collection | AccessorArrayLike; - -/** -* Integer index array. -*/ -type IntegerIndexArray = Collection | AccessorArrayLike; - -/** -* Index array. -*/ -type IndexArray = BooleanIndexArray | IntegerIndexArray; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing an object containing array index data. -*/ -interface BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IndexArray; - - /** - * The type of array index. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: DataType; -} - -/** -* Interface describing an object containing mask array data. -*/ -interface MaskArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Uint8Array; - - /** - * The type of array index. - */ - type: 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: 'uint8'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface Int32ArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Int32Array; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'int32'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface IntegerArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IntegerIndexArray; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Interface describing an object containing boolean array data. -*/ -interface BooleanArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: BooleanIndexArray; - - /** - * The type of array index. - */ - type: 'bool'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Array object data. -*/ -type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null; - -/** -* Interface describing an array index object. -*/ -interface BaseArrayIndex { - /** - * Read-only property returning the data associated with an `ArrayIndex` instance. - */ - data: IndexArray; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: DataType; - - /** - * Read-only property returning the unique identifier associated with an `ArrayIndex` instance. - */ - id: string; - - /** - * Boolean indicating if an `ArrayIndex` instance is actively cached. - */ - isCached: boolean; - - /** - * Read-only property returning the array index type. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * Serializes an `ArrayIndex` to a string. - * - * @returns serialized string - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * // returns - * - * var str = idx.toString(); - * // e.g., 'ArrayIndex<0>' - */ - toString(): string; -} - -/** -* Interface describing a mask array index object. -*/ -interface MaskArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'mask'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'uint8'; - - /** - * Read-only property returning the underlying array data. - */ - data: Uint8Array; -} - -/** -* Interface describing an integer array index object. -*/ -interface Int32ArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'int32'; - - /** - * Read-only property returning the underlying array data. - */ - data: Int32Array; -} - -/** -* Interface describing a boolean array index object. -*/ -interface BooleanArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'bool'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: BooleanIndexArray; -} - -/** -* Interface describing an integer array index object. -*/ -interface IntegerArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: IntegerIndexArray; -} - -/** -* Array index object. -*/ -type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex; - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0ddc494..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4a7842e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ba5c07c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 947639a4a5442da085805f08fe8317ba36349400 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 14:17:20 +0000 Subject: [PATCH 08/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 443 -- lib/validate.js | 66 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 87 - 56 files changed, 6213 insertions(+), 5282 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 670b71c..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 637d1f8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=o(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=o(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N -});var v=o(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=o(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=o(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=o(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,u,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(n=H(r),l=n(r,0),L(l))u="bool";else if(V(l))u="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else if(i==="int32")u="int";else if(i==="uint8")u="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:u,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cbaae39..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAK/B,GAJAD,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,UAE3ED,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICrZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d330d1f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType ArrayObject -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c4d6613..09ce019 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0ddc494 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4a7842e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index cb51518..0000000 --- a/lib/main.js +++ /dev/null @@ -1,443 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b617482..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1ac745e..7138725 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Array index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-copy": "^0.1.0", - "@stdlib/array-base-resolve-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-linked-list": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.1.0", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..80696d0 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index adb0867..0000000 --- a/test/test.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); From c8aee425f8eff146e1c7bc72930f2e1eacfae23c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 14:17:58 +0000 Subject: [PATCH 09/70] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf034e1..d8fc857 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage ```javascript -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.1.0-esm/index.mjs'; ``` @@ -417,7 +417,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.1.0-esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From a2457456e9460b53b132c074349fa9fe27ec7ac0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 Feb 2024 14:17:59 +0000 Subject: [PATCH 10/70] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d8fc857..ff06cb7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage +```javascript +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@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-index/tags). For example, + ```javascript import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.1.0-esm/index.mjs'; ``` @@ -417,7 +422,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.1.0-esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From 16ea376f7b263318e9d4d5022280214d0c5306d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:03:55 +0000 Subject: [PATCH 11/70] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 720c4cf..9880307 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.0", "@stdlib/assert-is-integer": "^0.2.0", "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", From 91945ea2e2bcc0939b3513765c8196f4fd66fd9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:35:29 +0000 Subject: [PATCH 12/70] Remove files --- index.d.ts | 539 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6721 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 09ce019..0000000 --- a/index.d.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; - -/** -* Boolean index array. -*/ -type BooleanIndexArray = Collection | AccessorArrayLike; - -/** -* Integer index array. -*/ -type IntegerIndexArray = Collection | AccessorArrayLike; - -/** -* Index array. -*/ -type IndexArray = BooleanIndexArray | IntegerIndexArray; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing an object containing array index data. -*/ -interface BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IndexArray; - - /** - * The type of array index. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: DataType; -} - -/** -* Interface describing an object containing mask array data. -*/ -interface MaskArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Uint8Array; - - /** - * The type of array index. - */ - type: 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: 'uint8'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface Int32ArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Int32Array; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'int32'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface IntegerArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IntegerIndexArray; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Interface describing an object containing boolean array data. -*/ -interface BooleanArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: BooleanIndexArray; - - /** - * The type of array index. - */ - type: 'bool'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Array object data. -*/ -type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null; - -/** -* Interface describing an array index object. -*/ -interface BaseArrayIndex { - /** - * Read-only property returning the data associated with an `ArrayIndex` instance. - */ - data: IndexArray; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: DataType; - - /** - * Read-only property returning the unique identifier associated with an `ArrayIndex` instance. - */ - id: string; - - /** - * Boolean indicating if an `ArrayIndex` instance is actively cached. - */ - isCached: boolean; - - /** - * Read-only property returning the array index type. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * Serializes an `ArrayIndex` to a string. - * - * @returns serialized string - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * // returns - * - * var str = idx.toString(); - * // e.g., 'ArrayIndex<0>' - */ - toString(): string; -} - -/** -* Interface describing a mask array index object. -*/ -interface MaskArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'mask'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'uint8'; - - /** - * Read-only property returning the underlying array data. - */ - data: Uint8Array; -} - -/** -* Interface describing an integer array index object. -*/ -interface Int32ArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'int32'; - - /** - * Read-only property returning the underlying array data. - */ - data: Int32Array; -} - -/** -* Interface describing a boolean array index object. -*/ -interface BooleanArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'bool'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: BooleanIndexArray; -} - -/** -* Interface describing an integer array index object. -*/ -interface IntegerArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: IntegerIndexArray; -} - -/** -* Array index object. -*/ -type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex; - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0ddc494..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.1.1-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4a7842e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 80696d0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30730e5a6eb1dbcd9012f59608023312a6ae6512 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:35:47 +0000 Subject: [PATCH 13/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 443 -- lib/validate.js | 66 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 87 - 56 files changed, 6213 insertions(+), 5282 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 670b71c..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 637d1f8..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=o(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=o(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N -});var v=o(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=o(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=o(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=o(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,u,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(n=H(r),l=n(r,0),L(l))u="bool";else if(V(l))u="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else if(i==="int32")u="int";else if(i==="uint8")u="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:u,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cbaae39..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAK/B,GAJAD,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,UAE3ED,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICrZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d330d1f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType ArrayObject -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c4d6613..09ce019 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eee1530 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4a7842e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index cb51518..0000000 --- a/lib/main.js +++ /dev/null @@ -1,443 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b617482..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9880307..7195625 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Array index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-copy": "^0.2.0", - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.0", - "@stdlib/array-to-json": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/utils-linked-list": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.1.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/assert-instance-of": "^0.2.0", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ab5098f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index adb0867..0000000 --- a/test/test.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); From 58a494844636914520e4a90c8ec34edfcf04ad00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:31:33 +0000 Subject: [PATCH 14/70] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d0261d..4ffc296 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage ```javascript -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.0-esm/index.mjs'; ``` @@ -417,7 +417,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.0-esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From 1e886ab180303ae00044741112488e7eaf9e83a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:31:34 +0000 Subject: [PATCH 15/70] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ffc296..d18d089 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage +```javascript +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@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-index/tags). For example, + ```javascript import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.0-esm/index.mjs'; ``` @@ -417,7 +422,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.0-esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From ca7893ee520ea0f885d665dfa96ddb74044d6d74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 07:58:12 +0000 Subject: [PATCH 16/70] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 878a667..9821068 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.0", "@stdlib/assert-is-integer": "^0.2.0", "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", From 0eb82bf6d866d5d462404c0a780e09cafc646228 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 07:58:43 +0000 Subject: [PATCH 17/70] Remove files --- index.d.ts | 539 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6721 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 09ce019..0000000 --- a/index.d.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; - -/** -* Boolean index array. -*/ -type BooleanIndexArray = Collection | AccessorArrayLike; - -/** -* Integer index array. -*/ -type IntegerIndexArray = Collection | AccessorArrayLike; - -/** -* Index array. -*/ -type IndexArray = BooleanIndexArray | IntegerIndexArray; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing an object containing array index data. -*/ -interface BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IndexArray; - - /** - * The type of array index. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: DataType; -} - -/** -* Interface describing an object containing mask array data. -*/ -interface MaskArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Uint8Array; - - /** - * The type of array index. - */ - type: 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: 'uint8'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface Int32ArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Int32Array; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'int32'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface IntegerArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IntegerIndexArray; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Interface describing an object containing boolean array data. -*/ -interface BooleanArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: BooleanIndexArray; - - /** - * The type of array index. - */ - type: 'bool'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Array object data. -*/ -type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null; - -/** -* Interface describing an array index object. -*/ -interface BaseArrayIndex { - /** - * Read-only property returning the data associated with an `ArrayIndex` instance. - */ - data: IndexArray; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: DataType; - - /** - * Read-only property returning the unique identifier associated with an `ArrayIndex` instance. - */ - id: string; - - /** - * Boolean indicating if an `ArrayIndex` instance is actively cached. - */ - isCached: boolean; - - /** - * Read-only property returning the array index type. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * Serializes an `ArrayIndex` to a string. - * - * @returns serialized string - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * // returns - * - * var str = idx.toString(); - * // e.g., 'ArrayIndex<0>' - */ - toString(): string; -} - -/** -* Interface describing a mask array index object. -*/ -interface MaskArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'mask'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'uint8'; - - /** - * Read-only property returning the underlying array data. - */ - data: Uint8Array; -} - -/** -* Interface describing an integer array index object. -*/ -interface Int32ArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'int32'; - - /** - * Read-only property returning the underlying array data. - */ - data: Int32Array; -} - -/** -* Interface describing a boolean array index object. -*/ -interface BooleanArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'bool'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: BooleanIndexArray; -} - -/** -* Interface describing an integer array index object. -*/ -interface IntegerArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: IntegerIndexArray; -} - -/** -* Array index object. -*/ -type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex; - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eee1530..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";function f(e,t){return u(t)?h(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,u,h;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(h=p(e)(e,0),i(h))u="bool";else{if(!s(h))throw new TypeError("invalid argument. First argument must be a valid index array.");u="int"}else if("int32"===l)u="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");u="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:u,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4a7842e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EAKxB,GAHAE,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MACK,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,ECvEO,CACNI,SAAW,GDuEPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ab5098f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a068f83ec2ddc579a28998b21b0f439e8514cebd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 07:59:05 +0000 Subject: [PATCH 18/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ---- test/test.validate.js | 126 - 57 files changed, 6213 insertions(+), 6524 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 670b71c..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9669690..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d330d1f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType ArrayObject -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c4d6613..09ce019 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5b707d7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";function f(e,t){return h(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,h,u;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(u=p(e)(e,0),i(u))h="bool";else{if(!s(u))throw new TypeError("invalid argument. First argument must be a valid index array.");h="int"}else h="int";else if("int32"===l)h="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");h="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:h,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a8a012 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EACxB,GAAKF,EAAEO,OAAS,EAKf,GAHAH,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,EC3EO,CACNI,SAAW,GD2EPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 49cad4f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b617482..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9821068..7195625 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Array index constructor.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-copy": "^0.2.0", - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.0", - "@stdlib/array-to-json": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/utils-linked-list": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/assert-instance-of": "^0.2.0", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a4c3489 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 1bc9dc3c98fa2a45c573ebb547ee4e171cc47a54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Feb 2024 07:45:50 +0000 Subject: [PATCH 19/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 878a667..9821068 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.0", "@stdlib/assert-is-integer": "^0.2.0", "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", From f6a3553a66c1919866665e6503f977b7b822eb64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Feb 2024 07:46:17 +0000 Subject: [PATCH 20/70] Remove files --- index.d.ts | 539 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6721 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 09ce019..0000000 --- a/index.d.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array'; - -/** -* Boolean index array. -*/ -type BooleanIndexArray = Collection | AccessorArrayLike; - -/** -* Integer index array. -*/ -type IntegerIndexArray = Collection | AccessorArrayLike; - -/** -* Index array. -*/ -type IndexArray = BooleanIndexArray | IntegerIndexArray; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing an object containing array index data. -*/ -interface BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IndexArray; - - /** - * The type of array index. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: DataType; -} - -/** -* Interface describing an object containing mask array data. -*/ -interface MaskArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Uint8Array; - - /** - * The type of array index. - */ - type: 'mask'; - - /** - * The data type of the underlying array. - */ - dtype: 'uint8'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface Int32ArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: Int32Array; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'int32'; -} - -/** -* Interface describing an object containing integer array data. -*/ -interface IntegerArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: IntegerIndexArray; - - /** - * The type of array index. - */ - type: 'int'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Interface describing an object containing boolean array data. -*/ -interface BooleanArrayObject extends BaseArrayObject { - /** - * The underlying array associated with an array index. - */ - data: BooleanIndexArray; - - /** - * The type of array index. - */ - type: 'bool'; - - /** - * The data type of the underlying array. - */ - dtype: 'generic'; -} - -/** -* Array object data. -*/ -type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null; - -/** -* Interface describing an array index object. -*/ -interface BaseArrayIndex { - /** - * Read-only property returning the data associated with an `ArrayIndex` instance. - */ - data: IndexArray; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: DataType; - - /** - * Read-only property returning the unique identifier associated with an `ArrayIndex` instance. - */ - id: string; - - /** - * Boolean indicating if an `ArrayIndex` instance is actively cached. - */ - isCached: boolean; - - /** - * Read-only property returning the array index type. - */ - type: 'int' | 'bool' | 'mask'; - - /** - * Serializes an `ArrayIndex` to a string. - * - * @returns serialized string - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * // returns - * - * var str = idx.toString(); - * // e.g., 'ArrayIndex<0>' - */ - toString(): string; -} - -/** -* Interface describing a mask array index object. -*/ -interface MaskArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'mask'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'uint8'; - - /** - * Read-only property returning the underlying array data. - */ - data: Uint8Array; -} - -/** -* Interface describing an integer array index object. -*/ -interface Int32ArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'int32'; - - /** - * Read-only property returning the underlying array data. - */ - data: Int32Array; -} - -/** -* Interface describing a boolean array index object. -*/ -interface BooleanArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'bool'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: BooleanIndexArray; -} - -/** -* Interface describing an integer array index object. -*/ -interface IntegerArrayIndex extends BaseArrayIndex { - /** - * Read-only property returning the array index type. - */ - type: 'int'; - - /** - * Read-only property returning the underlying array index data type. - */ - dtype: 'generic'; - - /** - * Read-only property returning the underlying array data. - */ - data: IntegerIndexArray; -} - -/** -* Array index object. -*/ -type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex; - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5b707d7..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";function f(e,t){return h(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(m("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",e.persist)):null:new TypeError(m("invalid argument. Options argument must be an object. Value: `%s`.",t))}var y=new v;function c(e){for(var t=y.first();t;){if(t.value.id===e)return t;t=t.next}return null}var j=-1;function b(){return(j+=1).toString()}function g(e){var a,d,l,h,u;if(!(this instanceof g))return arguments.length>1?new g(e,arguments[1]):new g(e);if(!n(e))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(u=p(e)(e,0),i(u))h="bool";else{if(!s(u))throw new TypeError("invalid argument. First argument must be a valid index array.");h="int"}else h="int";else if("int32"===l)h="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");h="mask"}if(a={persist:!1},arguments.length>1&&(d=f(a,arguments[1])))throw d;return y.push({id:b(),ref:this,data:e,type:h,dtype:l,persist:a.persist}),t(this,"_node",y.last()),r(this,"_invalidated",!1),this}t(g,"name","ArrayIndex"),t(g,"free",(function(e){var r,n;return null!==(r=c(e))&&(n=r.value,t(n.ref,"_invalidated",!0),y.remove(r),n.data=null,!0)})),t(g,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||g.free(e),r)})),e(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(g.prototype,"isCached",(function(){return!this._invalidated})),e(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(g.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a8a012..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/string-format';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n"],"names":["validate","opts","options","isObject","hasOwnProp","persist","isBoolean","TypeError","format","cache","LinkedList","find","id","node","first","value","next","COUNTER","toString","ArrayIndex","x","err","dt","t","v","this","arguments","length","isCollection","dtype","resolveGetter","get","isInteger","push","generateId","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;o+CAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SACjBC,EAAWL,EAAKI,UACd,IAAIE,UAAWC,EAAQ,+DAAgE,UAAWP,EAAKI,UAGzG,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC1BA,IAAIO,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EAef,SAASL,IAER,OADAK,GAAW,GACIC,UAChB,CCyBA,SAASC,EAAYC,GACpB,IAAInB,EACAoB,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBN,GACtB,OAAKO,UAAUC,OAAS,EAChB,IAAIR,EAAYC,EAAGM,UAAW,IAE/B,IAAIP,EAAYC,GAExB,IAAMQ,EAAcR,GACnB,MAAM,IAAIb,UAAWC,EAAQ,8EAA+EY,IAK7G,GAAY,aAHZE,EAAKO,EAAOT,KAGoB,OAAPE,EACxB,GAAKF,EAAEO,OAAS,EAKf,GAHAH,EADMM,EAAeV,EACjBW,CAAKX,EAAG,GAGPd,EAAWkB,GACfD,EAAI,WACE,KAAKS,EAAWR,GAGtB,MAAM,IAAIjB,UAAW,iEAFrBgB,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIf,UAAW,iEAFrBgB,EAAI,MAGJ,CAGD,GADAtB,EC3EO,CACNI,SAAW,GD2EPqB,UAAUC,OAAS,IACvBN,EAAMrB,EAAUC,EAAMyB,UAAW,KAEhC,MAAML,EAmBR,OAfAZ,EAAMwB,KAAK,CACVrB,GAAMsB,IACNC,IAAOV,KACPW,KAAQhB,EACRiB,KAAQd,EACRM,MAASP,EACTjB,QAAWJ,EAAKI,UAIjBiC,EAAab,KAAM,QAAShB,EAAM8B,QAGlCC,EAAkBf,KAAM,gBAAgB,GAEjCA,IACR,CAeAa,EAAanB,EAAY,OAAQ,cAwBjCmB,EAAanB,EAAY,QAAQ,SAAeP,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,MAIvBY,EAAIX,EAAKE,MAGTuB,EAAad,EAAEW,IAAK,gBAAgB,GAGpC1B,EAAMiC,OAAQ7B,GAGdW,EAAEY,KAAO,MAEF,EACR,IAiCAE,EAAanB,EAAY,OAAO,SAAcP,GAC7C,IAAIC,EACA8B,EACAnB,EAIJ,OAAc,QADdX,EAAO4B,EAAgB7B,IAEf,MAKR+B,EAAM,CACLP,MAJDZ,EAAIX,EAAKE,OAIEqB,KACVC,KAAQb,EAAEa,KACVR,MAASL,EAAEK,OAINL,EAAEnB,SACPc,EAAWyB,KAAMhC,GAEX+B,EACR,IAoBAE,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMqB,IACzB,IAoBAS,EAAqB1B,EAAW2B,UAAW,SAAS,WACnD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMc,KACzB,IAoBAgB,EAAqB1B,EAAW2B,UAAW,MAAM,WAChD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMH,EACzB,IAmBAiC,EAAqB1B,EAAW2B,UAAW,YAAY,WACtD,OAAQrB,KAAKsB,YACd,IAoBAF,EAAqB1B,EAAW2B,UAAW,QAAQ,WAClD,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAOvB,KAAKwB,MAAMlC,MAAMsB,IACzB,IAoBAC,EAAanB,EAAW2B,UAAW,YAAY,WAE9C,GAAKrB,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADHvB,KAAKwB,MAAMlC,MACUH,GAAK,GAC/B,IAwBA0B,EAAanB,EAAW2B,UAAW,UAAU,WAC5C,IAAItB,EAEJ,GAAKC,KAAKsB,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBZ,EAAIC,KAAKwB,MAAMlC,OACRc,OAAmC,OAAZL,EAAEK,MAC1BqB,EAAiB1B,EAAEY,MACnBe,EAAM3B,EAAEY,MAERZ,EAAEY,KAGHgB,EAAY5B,EAAEY,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a4c3489..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 445a37d9fb76677f4c680d2cbafa8756d32d6b17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Feb 2024 07:46:56 +0000 Subject: [PATCH 21/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 57 files changed, 4878 insertions(+), 6518 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -498,7 +489,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -563,9 +554,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..53b051a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9821068..7195625 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Array index constructor.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-copy": "^0.2.0", - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.0", - "@stdlib/array-to-json": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/utils-linked-list": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/assert-instance-of": "^0.2.0", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..08de58f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From a6e5549926373d0e383ece560a761c16a1ac2d68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 02:33:30 +0000 Subject: [PATCH 22/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 79d2cc0..2a6a41c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.0", "@stdlib/assert-is-integer": "^0.2.0", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From 872dfd09edb6c022f7d98187edbf8aacc4b543ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 02:33:55 +0000 Subject: [PATCH 23/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 53b051a..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.0-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 08de58f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 74bf4882d9238d1415fe943962827cce5ebf1968 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 02:34:30 +0000 Subject: [PATCH 24/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 57 files changed, 4878 insertions(+), 6518 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..89d7e5b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 2a6a41c..7195625 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Array index constructor.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-copy": "^0.2.0", - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.0", - "@stdlib/array-to-json": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fb12b30 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 8fb9bc3d040315d05cb66cf1b1c6e81835335c6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:48:13 +0000 Subject: [PATCH 25/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index f6f40d5..092eaeb 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From aac5519e38646164f2feb9695ce1ec6ad60b6dbc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:07:06 +0000 Subject: [PATCH 26/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 89d7e5b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fb12b30..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 606fe577719ce0026607a03a1e3e9954f13d5d13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:07:22 +0000 Subject: [PATCH 27/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 57 files changed, 4878 insertions(+), 6519 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f9e964c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 092eaeb..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..29da128 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 426330abffe3b737249418dc1a733c6a67d36688 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:47:19 +0000 Subject: [PATCH 28/70] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21fb0a4..212af91 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage ```javascript -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.1-esm/index.mjs'; ``` @@ -417,7 +417,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.1-esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From 83c118a32b3cec2aac7f5ad1d075fdbfff3812b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:47:20 +0000 Subject: [PATCH 29/70] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 212af91..c7d3341 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage +```javascript +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@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-index/tags). For example, + ```javascript import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.1-esm/index.mjs'; ``` @@ -417,7 +422,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.2.1-esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From 3d717216d036f17f3e9768e97efbd21a4c44c762 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:14:44 +0000 Subject: [PATCH 30/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 60773f1..1dc61f6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From cff929b277356c2d8b1c457632ede5a619ea6d27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:55:28 +0000 Subject: [PATCH 31/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f9e964c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 29da128..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 43602a2d2f2be7ef24fcfc4d367a8596fc98e5ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:55:44 +0000 Subject: [PATCH 32/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 58 files changed, 4878 insertions(+), 6521 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 6beda26..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:57:24.051Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c062979 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1dc61f6..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..652581a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 88c4f330151d2f6d72583e71129f7f1f2e95784f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:32:05 +0000 Subject: [PATCH 33/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 60773f1..1dc61f6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From a205c93b8dcac821d4a7ee79b0730c1c4a7d5204 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:01:39 +0000 Subject: [PATCH 34/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c062979..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 652581a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cabfc7f450ba343d3c2f8ff529120232ceb2286c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:01:57 +0000 Subject: [PATCH 35/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 58 files changed, 4878 insertions(+), 6524 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 9200332..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:14:02.289Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c062979 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1dc61f6..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..652581a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 21b9021b1af5ca944cba80f937d6f0745b470a76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:47:17 +0000 Subject: [PATCH 36/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 60773f1..1dc61f6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From 34a006b752fe7ec3d2bf2707fca34efbd7e8df53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:08:25 +0000 Subject: [PATCH 37/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c062979..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 652581a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ac76ccc32a83a976760ec1389858031bb3be736c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:08:44 +0000 Subject: [PATCH 38/70] 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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 15 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 189 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 57 files changed, 4878 insertions(+), 6525 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3a8c320..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){ -function A(){return{persist:!1}}p.exports=A -});var g=u(function($,h){ -var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N -});var v=u(function(ee,m){ -var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k -});var q=u(function(re,w){ -var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F -});var x=u(function(te,_){ -var b=-1;function R(){return b+=1,b.toString()}_.exports=R -});var O=u(function(ae,T){ -var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a -});var X=O();module.exports=X; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 890409c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - - new ArrayIndex( x ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x ); // $ExpectType IntegerArrayIndex - ArrayIndex( y ); // $ExpectType BooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType IntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType BooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); 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 faa9e92..6f3f996 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c062979 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1dc61f6..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..652581a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 7c7c8067108a811098abc312bb1b56c2d35d77fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 5 Jun 2024 05:19:39 +0000 Subject: [PATCH 39/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 49cad4f..f1a2fab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 60773f1..1dc61f6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From 8bb05518483e285b2dc688e49a432341654d26f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 5 Jun 2024 05:20:01 +0000 Subject: [PATCH 40/70] Remove files --- index.d.ts | 289 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5136 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 6f3f996..0000000 --- a/index.d.ts +++ /dev/null @@ -1,289 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c062979..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 652581a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 694629067cd38cd25703362bbde80042d7fe1597 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 5 Jun 2024 05:20:14 +0000 Subject: [PATCH 41/70] 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 | 109 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 195 - examples/index.js | 59 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 447 -- lib/validate.js | 66 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1198 ----- test/test.validate.js | 126 - 57 files changed, 4878 insertions(+), 6650 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 f92a6c5..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 + + ```
@@ -504,7 +495,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -569,9 +560,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1f0c8ad..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var q=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var b=-1;function R(){return b+=1,b.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),s=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2015079..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index be2e0de..0000000 --- a/examples/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c062979 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f200dea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f1a2fab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,447 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1dc61f6..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..652581a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e3cd5aa..0000000 --- a/test/test.js +++ /dev/null @@ -1,1198 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 0994db72f336870a78e0fd0d2df39e8e3a11c677 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:09:16 +0000 Subject: [PATCH 42/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 61b1129..d1fa61c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 47b6dab..b71153e 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From c97c2543b2f142ae43baac19ce935b93d56ac532 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:09:43 +0000 Subject: [PATCH 43/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c062979..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else{if("uint8"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="mask"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f200dea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,UACE,IAAY,UAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC3EO,CACNgB,SAAW,GD2EPV,UAAUC,OAAS,IACvBN,EE7DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFkDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,ID/EDK,GAAW,GACIyB,WC+EdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 652581a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b9dcf19badc9d9b99b799e10cca90c6b695bf2c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:10:01 +0000 Subject: [PATCH 44/70] 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 | 111 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ------ test/test.validate.js | 126 - 57 files changed, 4879 insertions(+), 6785 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 f92a6c5..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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 280b28d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..814c79f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5f1b48b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d1fa61c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b71153e..f44892b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-linked-list": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-bool": "github:stdlib-js/array-bool#main", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7e64e52 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 9bea6725ca0ef742c356fb66bd55c86eb4866546 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:15:38 +0000 Subject: [PATCH 45/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 61b1129..d1fa61c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 59250f3..a5a68e9 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 489054637b1fd25ea185a726c94b89c3cb23793c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:41:40 +0000 Subject: [PATCH 46/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 814c79f..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.1-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5f1b48b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7e64e52..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fc631d3d8348364a0e3c8fe119d0244601b6bc13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:41:54 +0000 Subject: [PATCH 47/70] 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 | 154 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ------ test/test.validate.js | 126 - 57 files changed, 4879 insertions(+), 6830 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 280b28d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..785cd0c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5f1b48b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d1fa61c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index a5a68e9..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6dbe783 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From c131a3279999f9d5c070e7499eb8259094a1e1db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:49:42 +0000 Subject: [PATCH 48/70] Update README.md for ESM bundle v0.3.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ca12e7..1153e21 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage ```javascript -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.3.0-esm/index.mjs'; ``` @@ -418,7 +418,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; import BooleanArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-bool@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.3.0-esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From efbe0d794c94e93e8f640610260708cad115a3e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:49:43 +0000 Subject: [PATCH 49/70] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1153e21..780f33e 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Specifically, instantiated `ArrayIndex` objects are assigned a unique identifier ## Usage +```javascript +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@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-index/tags). For example, + ```javascript import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.3.0-esm/index.mjs'; ``` @@ -418,7 +423,7 @@ var o = idx.toJSON(); import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import Int32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@esm/index.mjs'; import BooleanArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-bool@esm/index.mjs'; -import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@v0.3.0-esm/index.mjs'; +import ArrayIndex from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-index@esm/index.mjs'; var x = new Uint8Array( [ 1, 0, 1, 0 ] ); var i = new ArrayIndex( x ); From b62c900add41184d6eadf5d78c732e7f1eb7bb4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:23:27 +0000 Subject: [PATCH 50/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 61b1129..d1fa61c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index a83bb92..97578b4 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From c69a52f29bc1c465c02b1733b3d8a3957a8f4670 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:16:52 +0000 Subject: [PATCH 51/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 785cd0c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5f1b48b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6dbe783..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 85632823cfb42f376fc07659666d4cabae6fff14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:17:08 +0000 Subject: [PATCH 52/70] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ------ test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6755 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 4b6af6c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T06:07:06.467Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 280b28d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5f1b48b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d1fa61c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 97578b4..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..51a851e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From e4459ee5e31ce4d36be3eefb2b02d309cbe2f9c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:45:06 +0000 Subject: [PATCH 53/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 61b1129..d1fa61c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index 2f8fad7..5880bb2 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 3aa70bb9df6e25d36243383d83e886db6e756aa6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 13:13:36 +0000 Subject: [PATCH 54/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5f1b48b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 51a851e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 59ecaddd779446367220d8bc80d362c684f6c69a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 13:13:50 +0000 Subject: [PATCH 55/70] 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 | 154 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 202 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ------ test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6831 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 df822e5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:35:04.185Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 280b28d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e4cd7..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,202 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > // ... - > {{alias}}.free( idx.id ) - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5f1b48b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d1fa61c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5880bb2..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..51a851e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From c10cba15d3752b571e0d6bb116fcc5e9a644cd1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Dec 2024 01:30:22 +0000 Subject: [PATCH 56/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 61b1129..d1fa61c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index b17afc7..1a3f427 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 97159966be50ba6d44062170d0b7e110dbca5ecd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Dec 2024 01:30:51 +0000 Subject: [PATCH 57/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5f1b48b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 51a851e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f9a6d14c1b23a086aebddbb1b86c50f88a676855 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Dec 2024 01:31:19 +0000 Subject: [PATCH 58/70] 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 | 188 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 203 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ----- test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6970 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 280b28d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b4442db..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,203 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5f1b48b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d1fa61c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1a3f427..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..51a851e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 09183c759efcd3f0f6a95138390bd874c4b3aa45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Dec 2024 01:17:16 +0000 Subject: [PATCH 59/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8941519..16c7671 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -77,7 +77,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index b17afc7..1a3f427 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 97096b8c865795a8444303d2cf9f1d1fe242a55c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Dec 2024 01:17:42 +0000 Subject: [PATCH 60/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5f1b48b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 51a851e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9eadf3d1c8017de841c020de2328c0b4ba706575 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Dec 2024 01:18:16 +0000 Subject: [PATCH 61/70] 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 | 189 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 203 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 449 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ----- test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6971 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 307d85a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b4442db..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,203 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c9a2c3c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16c7671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,449 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of an array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of an array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of an array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1a3f427..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e99691 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From dcf217357ed4bd7d0b17f44fe6e07c2d48c340b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Dec 2024 21:39:48 +0000 Subject: [PATCH 62/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0517db5..4f6e9ea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -78,7 +78,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index b17afc7..1a3f427 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From b795ce6ef8290fdae944378ffb3fad5f745f5b92 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Dec 2024 21:40:11 +0000 Subject: [PATCH 63/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c9a2c3c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC2Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC7EO,CACNgB,SAAW,GD6EPV,UAAUC,OAAS,IACvBN,EE/DF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFoDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDjFDK,GAAW,GACIyB,WCiFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e99691..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cdfac01ca8fd1fb1a7e7e44a1c97a4c042d9a665 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Dec 2024 21:40:37 +0000 Subject: [PATCH 64/70] 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 | 190 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 203 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 450 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ----- test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6973 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 257be00..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IA0BjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC5ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b4442db..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,203 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd63f54 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC4Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC9EO,CACNgB,SAAW,GD8EPV,UAAUC,OAAS,IACvBN,EEhEF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFqDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDlFDK,GAAW,GACIyB,WCkFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f6e9ea..0000000 --- a/lib/main.js +++ /dev/null @@ -1,450 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @constructor -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of an array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of an array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of an array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1a3f427..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f4ade50 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 5d515d731bfd5451137757bdc452a150552d9a3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 00:09:34 +0000 Subject: [PATCH 65/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0517db5..4f6e9ea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -78,7 +78,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index b17afc7..1a3f427 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From d991772a90ca36b8ef93515a569b8941359c689c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 00:10:03 +0000 Subject: [PATCH 66/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd63f54..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC4Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC9EO,CACNgB,SAAW,GD8EPV,UAAUC,OAAS,IACvBN,EEhEF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFqDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDlFDK,GAAW,GACIyB,WCkFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f4ade50..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7434c9c4915b33a89098dd87523448953acc57c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 00:10:40 +0000 Subject: [PATCH 67/70] 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 | 191 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 203 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 450 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ----- test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6974 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 257be00..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IA0BjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC5ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b4442db..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,203 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7a6a21b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd63f54 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC4Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC9EO,CACNgB,SAAW,GD8EPV,UAAUC,OAAS,IACvBN,EEhEF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFqDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDlFDK,GAAW,GACIyB,WCkFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f6e9ea..0000000 --- a/lib/main.js +++ /dev/null @@ -1,450 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @constructor -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of an array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of an array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of an array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1a3f427..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f4ade50 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 598050c9d52f0cc3f329cabb7b7eebe44b76d763 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:44:51 +0000 Subject: [PATCH 68/70] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0517db5..4f6e9ea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var array2json = require( '@stdlib/array-to-json' ); var dtype = require( '@stdlib/array-dtype' ); var copy = require( '@stdlib/array-base-copy' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -78,7 +78,7 @@ function ArrayIndex( x ) { return new ArrayIndex( x ); } if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null2O', x ) ); } dt = dtype( x ); diff --git a/lib/validate.js b/lib/validate.js index b617482..dc894e5 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } return null; diff --git a/package.json b/package.json index b17afc7..1a3f427 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 3c6976ab3bc696a002f6048c90e79eda571290e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:45:17 +0000 Subject: [PATCH 69/70] Remove files --- index.d.ts | 325 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5172 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 85d7d37..0000000 --- a/index.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable". -*/ -interface Constructor { - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = new ArrayIndex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Uint8Array, options?: Options ): MaskArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * - * var x = new BooleanArray( [ true, false, true, false ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: BooleanArray, options?: Options ): BooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * - * var x = new Int32Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: Int32Array, options?: Options ): Int32ArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var x = [ true, false, true, false ]; - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = ArrayIndex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ArrayIndex; - - /** - * String value of the constructor name. - */ - name: 'ArrayIndex'; - - /** - * Frees the `ArrayIndex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ArrayIndex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ArrayIndex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns the array associated with a provided identifier. - * - * @param id - identifier - * @returns object containing array index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * - * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ArrayIndex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns [ 1, 0, 1, 0 ] - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Array index constructor. -* -* @param x - input array -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @returns ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7a6a21b..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd63f54..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC4Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC9EO,CACNgB,SAAW,GD8EPV,UAAUC,OAAS,IACvBN,EEhEF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFqDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDlFDK,GAAW,GACIyB,WCkFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f4ade50..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 966dbc213807ef5f03009f0e1dc63398cad825c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:45:44 +0000 Subject: [PATCH 70/70] 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 | 192 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 67 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 60 - benchmark/benchmark.dtype.js | 60 - benchmark/benchmark.get.js | 60 - benchmark/benchmark.id.js | 60 - benchmark/benchmark.is_cached.js | 60 - benchmark/benchmark.js | 84 - benchmark/benchmark.to_json.js | 60 - benchmark/benchmark.to_string.js | 60 - benchmark/benchmark.type.js | 60 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 203 - docs/types/test.ts | 195 - examples/index.js | 69 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/defaults.js | 42 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 43 - lib/main.js | 450 -- lib/validate.js | 66 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1317 ----- test/test.validate.js | 126 - 58 files changed, 4879 insertions(+), 6975 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.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/defaults.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 198710f..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/index) 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 8a1bc13..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/index) 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 b05baed..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: '6 6 * * 6' - - # 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 + + ```
@@ -514,7 +505,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -579,9 +570,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy +[@stdlib/array/to-fancy]: https://github.com/stdlib-js/array-to-fancy/tree/esm -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 4282faf..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return a collection' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 9016b17..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 1c538af..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - ( new ArrayIndex( [ 1, 2, 3 ], opts ) ).id, - ( new ArrayIndex( [ 5, 6, 7 ], opts ) ).id, - ( new ArrayIndex( [ true, false, true ], opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ArrayIndex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 16cddfd..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index e677ae1..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ad2d308..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ArrayIndex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var idx; - var v; - var i; - - idx = ArrayIndex; - - values = [ - [ 1, 2, 3 ], - [ 5, 6, 7 ], - [ true, false, true ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = idx( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ArrayIndex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 24b4a39..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 4d388a6..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index e6b234c..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ArrayIndex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v; - var i; - - opts = { - 'persist': true - }; - - values = [ - new ArrayIndex( [ 1, 2, 3 ], opts ), - new ArrayIndex( [ 5, 6, 7 ], opts ), - new ArrayIndex( [ true, false, true ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index bc8e788..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/index" -%% click B href "https://github.com/stdlib-js/array-index/tree/main" -%% click C href "https://github.com/stdlib-js/array-index/tree/production" -%% click D href "https://github.com/stdlib-js/array-index/tree/esm" -%% click E href "https://github.com/stdlib-js/array-index/tree/deno" -%% click F href "https://github.com/stdlib-js/array-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/index -[production-url]: https://github.com/stdlib-js/array-index/tree/production -[deno-url]: https://github.com/stdlib-js/array-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-index/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 213375d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 257be00..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IA0BjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,KAC/B,GAAKJ,EAAE,OAAS,EAKf,GAJAG,EAAMX,EAAeQ,CAAE,EACvBM,EAAIH,EAAKH,EAAG,CAAE,EAGTd,EAAWoB,CAAE,EACjBD,EAAI,eACOlB,EAAWmB,CAAE,EACxBD,EAAI,UAEJ,OAAM,IAAI,UAAW,+DAAgE,OAGtFA,EAAI,cAEMD,IAAO,QAClBC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,+DAAgE,EAItF,GADAJ,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,EAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAIR,OAAAN,EAAM,KAAK,CACV,GAAME,EAAW,EACjB,IAAO,KACP,KAAQE,EACR,KAAQK,EACR,MAASD,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDlB,EAAa,KAAM,QAASa,EAAM,KAAK,CAAE,EAGzCZ,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAagB,EAAY,OAAQ,YAAa,EAwB9ChB,EAAagB,EAAY,OAAQ,SAAeQ,EAAK,CACpD,IAAIC,EACAF,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,IAERF,EAAIE,EAAK,MAGTzB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCV,EAAM,OAAQY,CAAK,EAGnBF,EAAE,KAAO,KAEF,GACR,CAAC,EAiCDvB,EAAagB,EAAY,MAAO,SAAcQ,EAAK,CAClD,IAAIC,EACAC,EACAH,EAIJ,OADAE,EAAOX,EAAgBU,CAAG,EACrBC,IAAS,KACN,MAERF,EAAIE,EAAK,MAGTC,EAAM,CACL,KAAQH,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPP,EAAW,KAAMQ,CAAG,EAEdE,EACR,CAAC,EAoBD3B,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,QAAS,UAAe,CAClE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,KAAM,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC5ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b4442db..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,203 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an array index object. - - Array index instances have no explicit functionality; however, they are used - by "fancy" arrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying array are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped array, as the consumer will attempt to resolve an instance - in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the array associated with the instance having a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing array data. - - out.data: Array|TypedArray|Object - The underlying array associated with the provided identifier. - - out.type: string - The type of array index. - - out.dtype: string - The data type of the underlying array. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.prototype.data - Read-only property returning the underlying index array. - - Returns - ------- - out: Array|TypedArray|Object - Array data. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.data - [ 1, 2, 3, 4 ] - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index array. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.dtype - 'generic' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an array index is - actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an array index is actively cached. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.isCached - true - - -{{alias}}.prototype.type - Read-only property returning the array index type. - - Returns - ------- - out: string - Array index type. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var idx = new {{alias}}( [ 1, 2, 3, 4 ] ); - > idx.toJSON() - { 'type': 'ArrayIndex', 'data': [ 1, 2, 3, 4 ] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 7e3ad7f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import BooleanArray = require( '@stdlib/array-bool' ); -import ArrayIndex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - new ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z ); // $ExpectType MaskArrayIndex - new ArrayIndex( w ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - new ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - new ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z ); // $ExpectType MaskArrayIndex - ArrayIndex( w ); // $ExpectType Int32ArrayIndex - ArrayIndex( v ); // $ExpectType BooleanArrayIndex - - ArrayIndex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ArrayIndex( y, { 'persist': true } ); // $ExpectType GenericBooleanArrayIndex - ArrayIndex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ArrayIndex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ArrayIndex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid collection... -{ - ArrayIndex( 'abc' ); // $ExpectError - ArrayIndex( 1 ); // $ExpectError - ArrayIndex( null ); // $ExpectError - ArrayIndex( void 0 ); // $ExpectError - ArrayIndex( true ); // $ExpectError - ArrayIndex( false ); // $ExpectError - ArrayIndex( {} ); // $ExpectError - ArrayIndex( [ {} ] ); // $ExpectError - ArrayIndex( ( x: number ): number => x ); // $ExpectError - - ArrayIndex( 'abc', {} ); // $ExpectError - ArrayIndex( 1, {} ); // $ExpectError - ArrayIndex( null, {} ); // $ExpectError - ArrayIndex( void 0, {} ); // $ExpectError - ArrayIndex( true, {} ); // $ExpectError - ArrayIndex( false, {} ); // $ExpectError - ArrayIndex( {}, {} ); // $ExpectError - ArrayIndex( [ {} ], {} ); // $ExpectError - ArrayIndex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, 'abc' ); // $ExpectError - ArrayIndex( x, 1 ); // $ExpectError - ArrayIndex( x, null ); // $ExpectError - ArrayIndex( x, true ); // $ExpectError - ArrayIndex( x, false ); // $ExpectError - ArrayIndex( x, [ {} ] ); // $ExpectError - ArrayIndex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex( x, { 'persist': 'abc' } ); // $ExpectError - ArrayIndex( x, { 'persist': 1 } ); // $ExpectError - ArrayIndex( x, { 'persist': null } ); // $ExpectError - ArrayIndex( x, { 'persist': {} } ); // $ExpectError - ArrayIndex( x, { 'persist': [] } ); // $ExpectError - ArrayIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = [ 1, 2, 3, 4 ]; - - ArrayIndex(); // $ExpectError - ArrayIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ArrayIndex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ArrayIndex.free( 1 ); // $ExpectError - ArrayIndex.free( null ); // $ExpectError - ArrayIndex.free( void 0 ); // $ExpectError - ArrayIndex.free( true ); // $ExpectError - ArrayIndex.free( false ); // $ExpectError - ArrayIndex.free( {} ); // $ExpectError - ArrayIndex.free( [] ); // $ExpectError - ArrayIndex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ArrayIndex.free(); // $ExpectError - ArrayIndex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ArrayIndex.get( 1 ); // $ExpectError - ArrayIndex.get( null ); // $ExpectError - ArrayIndex.get( void 0 ); // $ExpectError - ArrayIndex.get( true ); // $ExpectError - ArrayIndex.get( false ); // $ExpectError - ArrayIndex.get( {} ); // $ExpectError - ArrayIndex.get( [] ); // $ExpectError - ArrayIndex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ArrayIndex.get(); // $ExpectError - ArrayIndex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a collection... -{ - const x = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - - x.data; // $ExpectType Uint8Array -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ArrayIndex( [ 1, 2, 3, 4 ] ); - - x.isCached; // $ExpectType boolean -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fdfb54d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayIndex = require( './../lib' ); - -var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -var i = new ArrayIndex( x ); -// returns - -var o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ true, false, true, false ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new BooleanArray( [ true, false, true, false ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = new Int32Array( [ 1, 3, 4, 7 ] ); -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = [ 1, 3, 4, 7 ]; -i = new ArrayIndex( x ); -// returns - -o = ArrayIndex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index c41d8bc..85d7d37 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1d6a432 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=new v;function y(e){for(var t=f.first();t;){if(t.value.id===e)return t;t=t.next}return null}var c=-1;function j(e){var a,d,l,v,y;if(!(this instanceof j))return arguments.length>1?new j(e,arguments[1]):new j(e);if(!n(e))throw new TypeError(h("null2O",e));if("generic"===(l=o(e))||null===l)if(e.length>0)if(y=p(e)(e,0),i(y))v="bool";else{if(!s(y))throw new TypeError("invalid argument. First argument must be a valid index array.");v="int"}else v="int";else if("int32"===l)v="int";else if("uint8"===l)v="mask";else{if("bool"!==l)throw new TypeError("invalid argument. First argument must be a valid index array.");v="bool"}if(a={persist:!1},arguments.length>1&&(d=function(e,t){return m(t)?u(t,"persist")&&(e.persist=t.persist,!i(e.persist))?new TypeError(h("null2o","persist",e.persist)):null:new TypeError(h("null2V",t))}(a,arguments[1]),d))throw d;return f.push({id:(c+=1).toString(),ref:this,data:e,type:v,dtype:l,persist:a.persist}),t(this,"_node",f.last()),r(this,"_invalidated",!1),this}t(j,"name","ArrayIndex"),t(j,"free",(function(e){var r,n;return null!==(r=y(e))&&(n=r.value,t(n.ref,"_invalidated",!0),f.remove(r),n.data=null,!0)})),t(j,"get",(function(e){var t,r,n;return null===(t=y(e))?null:(r={data:(n=t.value).data,type:n.type,dtype:n.dtype},n.persist||j.free(e),r)})),e(j.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data})),e(j.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype})),e(j.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id})),e(j.prototype,"isCached",(function(){return!this._invalidated})),e(j.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type})),t(j.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return"ArrayIndex<"+this._node.value.id+">"})),t(j.prototype,"toJSON",(function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return{type:"ArrayIndex",data:"generic"===(e=this._node.value).dtype||null===e.dtype?a(e.data)?l(e.data):e.data:d(e.data)}}));export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd63f54 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/validate.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport array2json from '@stdlib/array-to-json';\nimport dtype from '@stdlib/array-dtype';\nimport copy from '@stdlib/array-base-copy';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findArrayIndex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @constructor\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns \n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'null2O', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns [ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of an array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var v = idx.data;\n* // returns [ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of an array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of an array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* import Uint8Array from '@stdlib/array-uint8';\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ArrayIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["cache","LinkedList","find","id","node","first","value","next","COUNTER","ArrayIndex","x","opts","err","dt","t","v","this","arguments","length","isCollection","TypeError","format","dtype","resolveGetter","get","isBoolean","isInteger","persist","options","isObject","hasOwnProp","validate","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","findArrayIndex","remove","out","free","setReadOnlyAccessor","prototype","_invalidated","Error","_node","isAccessorArray","copy","array2json"],"mappings":";;6+CAkCA,IAAIA,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC4Cf,SAASC,EAAYC,GACpB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBP,GACtB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,EAAYC,EAAGO,UAAW,IAE/B,IAAIR,EAAYC,GAExB,IAAMS,EAAcT,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAKxC,GAAY,aAHZG,EAAKS,EAAOZ,KAGoB,OAAPG,EACxB,GAAKH,EAAEQ,OAAS,EAKf,GAHAH,EADMQ,EAAeb,EACjBc,CAAKd,EAAG,GAGPe,EAAWV,GACfD,EAAI,WACE,KAAKY,EAAWX,GAGtB,MAAM,IAAIK,UAAW,iEAFrBN,EAAI,KAGJ,MAEDA,EAAI,WAEC,GAAY,UAAPD,EACXC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,iEAFrBN,EAAI,MAGJ,CAGD,GADAH,EC9EO,CACNgB,SAAW,GD8EPV,UAAUC,OAAS,IACvBN,EEhEF,SAAmBD,EAAMiB,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBjB,EAAKgB,QAAUC,EAAQD,SACjBF,EAAWd,EAAKgB,UACd,IAAIP,UAAWC,EAAQ,SAAU,UAAWV,EAAKgB,UAGnD,KARC,IAAIP,UAAWC,EAAQ,SAAUO,GAS1C,CFqDQG,CAAUpB,EAAMM,UAAW,IAC5BL,GACJ,MAAMA,EAmBR,OAfAZ,EAAMgC,KAAK,CACV7B,IDlFDK,GAAW,GACIyB,WCkFdC,IAAOlB,KACPmB,KAAQzB,EACR0B,KAAQtB,EACRQ,MAAST,EACTc,QAAWhB,EAAKgB,UAIjBU,EAAarB,KAAM,QAAShB,EAAMsC,QAGlCC,EAAkBvB,KAAM,gBAAgB,GAEjCA,IACR,CAeAqB,EAAa5B,EAAY,OAAQ,cAwBjC4B,EAAa5B,EAAY,QAAQ,SAAeN,GAC/C,IAAIC,EACAW,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,MAIvBY,EAAIX,EAAKE,MAGT+B,EAAatB,EAAEmB,IAAK,gBAAgB,GAGpClC,EAAMyC,OAAQrC,GAGdW,EAAEoB,KAAO,MAEF,EACR,IAiCAE,EAAa5B,EAAY,OAAO,SAAcN,GAC7C,IAAIC,EACAsC,EACA3B,EAIJ,OAAc,QADdX,EAAOoC,EAAgBrC,IAEf,MAKRuC,EAAM,CACLP,MAJDpB,EAAIX,EAAKE,OAIE6B,KACVC,KAAQrB,EAAEqB,KACVd,MAASP,EAAEO,OAINP,EAAEY,SACPlB,EAAWkC,KAAMxC,GAEXuC,EACR,IAoBAE,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM6B,IACzB,IAoBAS,EAAqBnC,EAAWoC,UAAW,SAAS,WACnD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMgB,KACzB,IAoBAsB,EAAqBnC,EAAWoC,UAAW,MAAM,WAChD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAMH,EACzB,IAmBAyC,EAAqBnC,EAAWoC,UAAW,YAAY,WACtD,OAAQ7B,KAAK8B,YACd,IAoBAF,EAAqBnC,EAAWoC,UAAW,QAAQ,WAClD,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAElB,OAAO/B,KAAKgC,MAAM1C,MAAM8B,IACzB,IAoBAC,EAAa5B,EAAWoC,UAAW,YAAY,WAE9C,GAAK7B,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAGlB,MAAO,cADH/B,KAAKgC,MAAM1C,MACUH,GAAK,GAC/B,IAwBAkC,EAAa5B,EAAWoC,UAAW,UAAU,WAC5C,IAAI9B,EAEJ,GAAKC,KAAK8B,aACT,MAAM,IAAIC,MAAO,kGAYlB,MAAO,CACNX,KAAQ,aACRD,KAXgB,aADjBpB,EAAIC,KAAKgC,MAAM1C,OACRgB,OAAmC,OAAZP,EAAEO,MAC1B2B,EAAiBlC,EAAEoB,MACnBe,EAAMnC,EAAEoB,MAERpB,EAAEoB,KAGHgB,EAAYpC,EAAEoB,MAMpB"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 93744a9..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index arrays. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 44fa8dc..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index 3e14813..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an array index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} array index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 559d86e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Array index constructor. -* -* @module @stdlib/array-index -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ArrayIndex = require( '@stdlib/array-index' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f6e9ea..0000000 --- a/lib/main.js +++ /dev/null @@ -1,450 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var dtype = require( '@stdlib/array-dtype' ); -var copy = require( '@stdlib/array-base-copy' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findArrayIndex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* Array index constructor. -* -* @constructor -* @param {Collection} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} first argument must be a valid index array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayIndex} ArrayIndex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var x = new Uint8Array( [ 1, 0, 1, 0 ] ); -* -* var idx = new ArrayIndex( x ); -* // returns -*/ -function ArrayIndex( x ) { - var opts; - var err; - var get; - var dt; - var t; - var v; - if ( !(this instanceof ArrayIndex) ) { - if ( arguments.length > 1 ) { - return new ArrayIndex( x, arguments[ 1 ] ); - } - return new ArrayIndex( x ); - } - if ( !isCollection( x ) ) { - throw new TypeError( format( 'null2O', x ) ); - } - dt = dtype( x ); - - // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array... - if ( dt === 'generic' || dt === null ) { - if ( x.length > 0 ) { - get = resolveGetter( x ); - v = get( x, 0 ); - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - } else { - t = 'int'; - } - } else if ( dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index array.' ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Add the array index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': x, - 'type': t, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ArrayIndex -* @readonly -* @type {string} -* @default 'ArrayIndex' -* -* @example -* var str = ArrayIndex.name; -* // returns 'ArrayIndex' -*/ -setReadOnly( ArrayIndex, 'name', 'ArrayIndex' ); - -/** -* Frees an array index object associated with a provided identifier. -* -* @name free -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an array index object was successfully freed -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ArrayIndex.free( idx.id ); -* // returns true -*/ -setReadOnly( ArrayIndex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the array instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the array instance from the cache: - cache.remove( node ); - - // Remove the reference to the original array: - v.data = null; - - return true; -}); - -/** -* Returns the array associated with a provided identifier. -* -* @name get -* @memberof ArrayIndex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing array index data -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ArrayIndex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns [ 1, 0, 1, 0 ] -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ArrayIndex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the array index object with the specified identifier: - node = findArrayIndex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'dtype': v.dtype - }; - - // If the array index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data - } - return out; -}); - -/** -* Returns the underlying array data of an array index object. -* -* @name data -* @memberof ArrayIndex.prototype -* @readonly -* @type {Collection} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var v = idx.data; -* // returns [ 1, 0, 1, 0 ] -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying array data type of an array index object. -* -* @name dtype -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an array index object. -* -* @name id -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an array index is actively cached. -* -* @name isCached -* @memberof ArrayIndex.prototype -* @readonly -* @type {boolean} -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the type of an array index object. -* -* @name type -* @memberof ArrayIndex.prototype -* @readonly -* @type {string} -* @throws {Error} array index is no longer valid -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an array index object to a string. -* -* @name toString -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {string} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ArrayIndex<0>' -*/ -setReadOnly( ArrayIndex.prototype, 'toString', function toString() { - var v; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - return 'ArrayIndex<' + v.id + '>'; -}); - -/** -* Serializes an array index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance. -* -* @name toJSON -* @memberof ArrayIndex.prototype -* @type {Function} -* @throws {Error} array index is no longer valid -* @returns {Object} serialized array index object -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* -* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } } -*/ -setReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() { - var v; - var o; - if ( this._invalidated ) { - throw new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' ); - } - v = this._node.value; - if ( v.dtype === 'generic' || v.dtype === null ) { - if ( isAccessorArray( v.data ) ) { - o = copy( v.data ); - } else { - o = v.data; - } - } else { - o = array2json( v.data ); - } - return { - 'type': 'ArrayIndex', - 'data': o - }; -}); - - -// EXPORTS // - -module.exports = ArrayIndex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index dc894e5..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1a3f427..b464351 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.0", "description": "Array index constructor.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-string": "^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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f4ade50 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index beaec56..0000000 --- a/test/test.js +++ /dev/null @@ -1,1317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array2json = require( '@stdlib/array-to-json' ); -var ArrayIndex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ArrayIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var x; - - x = new ArrayIndex( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = new ArrayIndex( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ] ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ) ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var idx; - var x; - - idx = ArrayIndex; - - x = idx( [ 1, 2, 3 ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( [ true, false, true ], {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( toAccessorArray( [ 1, 2, 3 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Uint8Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new BooleanArray( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - x = idx( new Int32Array( [ 1, 0, 1 ] ), {} ); - t.strictEqual( instanceOf( x, ArrayIndex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index array (options)', function test( t ) { - var values; - var i; - - values = [ - [ 'a', 'b', 'c' ], - new Float64Array( [ 1.0, 2.0, 3.0 ] ), - [ 1.5, 2.5, 3.5 ], - [ null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ArrayIndex( [ 1, 2, 3 ], { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns the underlying index array', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index array data type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, null, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the array index identifier', function test( t ) { - var obj; - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ArrayIndex( [ 1, 2, 3 ] ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an array index is actively cached', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the array index type', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = []; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = []; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Uint8Array( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( /ArrayIndex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ true, false, true, false ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': [ 1, 2, 3 ] - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'type': 'ArrayIndex', - 'data': array2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - ArrayIndex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ArrayIndex.name, 'ArrayIndex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (non-persisted)', function test( t ) { - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index array (persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'persist': true - }; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ArrayIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index array has already been freed', function test( t ) { - var actual; - var idx; - var id; - var x; - - // Generic: - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = new BooleanArray( [ true, false, true, false ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ArrayIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ArrayIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index array data', function test( t ) { - var expected; - var actual; - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': null - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'generic' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'dtype': 'bool' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'dtype': 'uint8' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'dtype': 'int32' - }; - actual = ArrayIndex.get( idx.id ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.strictEqual( actual.data, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index arrays', function test( t ) { - var idx; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index arrays', function test( t ) { - var idx; - var x; - var i; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ArrayIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ArrayIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index array', function test( t ) { - var actual; - var idx; - var id; - var x; - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ 1, 2, 3 ]; - idx = new ArrayIndex( x, { - 'persist': true - }); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = [ true, false, true, false ]; - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new BooleanArray( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Uint8Array( [ 1, 0, 1, 0 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3 ] ); - idx = new ArrayIndex( x ); - - id = idx.id; - ArrayIndex.free( id ); - actual = ArrayIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ArrayIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index ccc8296..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true - }; - opts = {}; - - expected = { - 'persist': true - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -});