From a3250ae4ac1866790a7a6c33566c9e0772ea6314 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 19 Dec 2023 12:02:58 +0000 Subject: [PATCH 01/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c06d2f1..bc8df26 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.1.0", "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.1.0", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c0a15eb56d0f31c33aee4d3cb18531659dd5827e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 19 Dec 2023 12:03:53 +0000 Subject: [PATCH 02/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 42 files changed, 6199 insertions(+), 4280 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2462697..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: '34 22 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -203,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 3774e15..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..de8378b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index bc8df26..182afd6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..82ad098 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 12858a479fdc7021569fd2e6c16be48c1781af46 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:19:15 +0000 Subject: [PATCH 03/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ec53724..134552f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.1.0", "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.1.0", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 4988684c6b3f56a3784748fafa4a2f6fc8a688b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:19:49 +0000 Subject: [PATCH 04/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6241 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index de8378b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 82ad098..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ce6537332442f8d90f412044c75462a6e0b05806 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:20:17 +0000 Subject: [PATCH 05/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 42 files changed, 6199 insertions(+), 4280 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2462697..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: '34 22 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -203,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 3774e15..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..de8378b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 134552f..bd09cec 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4a4eed1 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From e1605041b308651e35528d3990cc695305be2120 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:21:05 +0000 Subject: [PATCH 06/55] 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 a6565a4..55f1861 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@esm/index.mjs'; +import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@v0.1.0-esm/index.mjs'; ``` #### lastIndexOf( x, searchElement, fromIndex, equalNaNs ) @@ -143,7 +143,7 @@ idx = lastIndexOf( x, NaN, 5, true ); - - - - From 88dc866ef2622d519ef99aa4cf06889deb67b4e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 16:03:09 +0000 Subject: [PATCH 10/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 43 files changed, 6199 insertions(+), 4281 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dcf6ef6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T06:04:50.275Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 9b3dad0..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: '34 22 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -203,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 3774e15..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..77ad127 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 134552f..bd09cec 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..13af941 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 008da651791bf9ae7a4f19b85f60eb81066d7cbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:45:23 +0000 Subject: [PATCH 11/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e06ead4..2de23d6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.0", "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/types": "^0.3.1" + "@stdlib/types": "^0.3.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.1.0", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 4def9fd5d88ecaed8b4cfbd857ec4c97b6d448a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:30:01 +0000 Subject: [PATCH 12/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6241 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 77ad127..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 13af941..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8a34093dd2754d77423d6d6f750311c0f6b062de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:30:42 +0000 Subject: [PATCH 13/55] 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 | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 42 files changed, 6199 insertions(+), 4289 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 566b034..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..99e03f5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.0-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 2de23d6..03945ae 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.0", - "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.1.0", - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3687601 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 80cc1c7490a75c162935181a2c42c7498702df27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:52:31 +0000 Subject: [PATCH 14/55] 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 687666d..dcc4700 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@esm/index.mjs'; +import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@v0.2.0-esm/index.mjs'; ``` #### lastIndexOf( x, searchElement, fromIndex, equalNaNs ) @@ -143,7 +143,7 @@ idx = lastIndexOf( x, NaN, 5, true ); - - - - From d33d43c0e218e86b6a94f703454edbf16e045a35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:20:23 +0000 Subject: [PATCH 18/55] 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 | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 42 files changed, 4864 insertions(+), 4283 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2bffb52 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 9bb9b94..1c991ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.0", - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a088767 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From fe7f8a04a0ab88b8e3084a2cf332d51e4ba04699 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:34:35 +0000 Subject: [PATCH 19/55] 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 e868380..00d81e2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@esm/index.mjs'; +import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@v0.2.1-esm/index.mjs'; ``` #### lastIndexOf( x, searchElement, fromIndex, equalNaNs ) @@ -143,7 +143,7 @@ idx = lastIndexOf( x, NaN, 5, true ); - - - - From feb18fa7ba6135407f2b79658c1289ff28cc7b39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 14:14:21 +0000 Subject: [PATCH 23/55] 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 | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 43 files changed, 4864 insertions(+), 4288 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1d4de9e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:54:23.737Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2bffb52 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index aec326a..1c991ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a088767 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 2b9057f65c96113727b3dc2537c6fc79de381574 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 20:51:03 +0000 Subject: [PATCH 24/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce4bdf4..aec326a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.1", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From a7c2d46641465f0703ec89b2683ddf9d69807e90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 20:51:32 +0000 Subject: [PATCH 25/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2bffb52..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a088767..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e3fa858820175acef111438d430b5247825e8552 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 20:51:56 +0000 Subject: [PATCH 26/55] 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 | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 422 -- 42 files changed, 4864 insertions(+), 4287 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2bffb52 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index aec326a..1c991ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a088767 --- /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 f28ce33..0000000 --- a/test/test.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From c61f3b227e0fc79d543b1778ddbf590138f97f04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 21:38:04 +0000 Subject: [PATCH 27/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce4bdf4..aec326a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.1", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 41952caf043aa7b4da525683cfd10decf2de8091 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 21:38:32 +0000 Subject: [PATCH 28/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2bffb52..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a088767..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9872a5f009b893925323c6a9190427231d97fe17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Apr 2024 21:38:47 +0000 Subject: [PATCH 29/55] 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 | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 42 files changed, 4864 insertions(+), 4302 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2bffb52 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index aec326a..1c991ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a088767 --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From a1a375177444138df518c85fc8e433b51c374185 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 04:39:34 +0000 Subject: [PATCH 30/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ce4bdf4..aec326a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.1", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 0e82dc02c9d65dcdca480aa68a53ad34cbd966b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 10:22:09 +0000 Subject: [PATCH 31/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2bffb52..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a088767..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0862b51e795e39f540d3b4e4af5e55785d1ffcc3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 10:22:23 +0000 Subject: [PATCH 32/55] 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 | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 42 files changed, 4864 insertions(+), 4304 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2bffb52 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index aec326a..1c991ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-pow": "^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", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a088767 --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From ace21b149cdf33570c04e785da1b6a659f1440d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 11:58:56 +0000 Subject: [PATCH 33/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b064a66..3930918 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.1", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ad62f39c422a8c54c8ae671e5a15a0c7d2e2e1cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:06:23 +0000 Subject: [PATCH 34/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2bffb52..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a088767..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fb4b1ac5216eafdf8040d965f978920789ba741a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:06:38 +0000 Subject: [PATCH 35/55] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 42 files changed, 4864 insertions(+), 4415 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2f95c19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 3930918..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6a136e --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 0c1267d8c720a9d16db3863b1a986924cea90464 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:08:11 +0000 Subject: [PATCH 36/55] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 437d5c5..ce0fe9e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@esm/index.mjs'; +import lastIndexOf from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-last-index-of@v0.2.2-esm/index.mjs'; ``` #### lastIndexOf( x, searchElement, fromIndex, equalNaNs ) @@ -143,7 +143,7 @@ idx = lastIndexOf( x, NaN, 5, true ); - - - - From e1bd702d0b65e6165f4d8f1e160bff20de93b0ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:51:13 +0000 Subject: [PATCH 40/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 44 files changed, 4864 insertions(+), 4521 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7184de8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-23T02:10:25.321Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2f95c19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index cb3630c..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6a136e --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 77cca51572fe4e497e5cd64f488ac3d5fe466d0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:54:00 +0000 Subject: [PATCH 41/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 19f3d8d..cb3630c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.2", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1a75686355e6ee5d49342c57cd8244cc07cdb3f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 02:10:14 +0000 Subject: [PATCH 42/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2f95c19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a6a136e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f2266f916eac3aa2dd5f6b53c592770ac255c65e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 02:10:28 +0000 Subject: [PATCH 43/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 44 files changed, 4864 insertions(+), 4520 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 32d2860..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:46:49.798Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58c6eb7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5cf298c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index cb3630c..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6a136e --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 1841b683759af0fbb7a9b2860c16cdfc0a9c239d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:07:54 +0000 Subject: [PATCH 44/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 19f3d8d..cb3630c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.2", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ee7adf5c1336cf02100fd9d7416131069c6588ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 03:08:10 +0000 Subject: [PATCH 45/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5cf298c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a6a136e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 78ac610b570a12973ad7239cbe733878ca1b8cd6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 03:08:23 +0000 Subject: [PATCH 46/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 99 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 179 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 437 -- 44 files changed, 4864 insertions(+), 4524 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3dd84f0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:49:38.175Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d0f3637..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -205,7 +196,7 @@ idx = lastIndexOf( x, 'foo', -50, false ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index b2aa3b6..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1, false ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,equal_nans=false,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e1bb7a2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var o=c(function(y,s){ -var v=require('@stdlib/array-base-arraylike2object/dist'),a=require('@stdlib/math-base-assert-is-nan/dist');function l(t,i){return typeof t[i]=="function"}function g(t,i,n,e){var r;if(e&&a(i)){for(r=n;r>=0;r--)if(a(t[r]))return r;return-1}for(r=n;r>=0;r--)if(i===t[r])return r;return-1}function p(t,i,n,e){var r,f,u;if(r=t.data,f=t.accessors[0],e&&a(i)){for(u=n;u>=0;u--)if(a(f(r,u)))return u;return-1}for(u=n;u>=0;u--)if(i===f(r,u))return u;return-1}function O(t,i,n,e){var r;if(l(t,"lastIndexOf")&&e===!1)return t.lastIndexOf(i,n);if(n<0){if(n+=t.length,n<0)return-1}else n>t.length&&(n=t.length-1);return r=v(t),r.accessorProtocol?p(r,i,n,e):g(t,i,n,e)}s.exports=O -});var b=o();module.exports=b; -/** @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 93b0640..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,GAAK,EAAGA,IAC5B,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAAaR,EAAGC,EAAeC,EAAWC,EAAY,CAC9D,IAAIN,EACJ,GAAKD,EAAWI,EAAG,aAAc,GAAKG,IAAc,GACnD,OAAOH,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,CACzD,CAKAV,EAAO,QAAUe,IC9IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f79d3e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex, equalNaNs ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method and - `equalNaNs` is `false`, the function defers execution to that method and - assumes that the method has the following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method or if - `equalNaNs` is `true`, the function performs a linear scan and returns - immediately upon finding a match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - equalNaNs: boolean - Boolean indicating whether NaNs should be considered equal. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3, false ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c7644d2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, false ); // $ExpectType number - - lastIndexOf( [ 1, 2, 3 ], 0, 3, true ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3, true ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3, false ); // $ExpectError - lastIndexOf( true, 0, 3, false ); // $ExpectError - lastIndexOf( false, 0, 3, false ); // $ExpectError - lastIndexOf( null, 0, 3, false ); // $ExpectError - lastIndexOf( void 0, 0, 3, false ); // $ExpectError - lastIndexOf( {}, 0, 3, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5', false ); // $ExpectError - lastIndexOf( x, 0, true, false ); // $ExpectError - lastIndexOf( x, 0, false, false ); // $ExpectError - lastIndexOf( x, 0, null, false ); // $ExpectError - lastIndexOf( x, 0, void 0, false ); // $ExpectError - lastIndexOf( x, 0, [], false ); // $ExpectError - lastIndexOf( x, 0, {}, false ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, 0, 5 ); // $ExpectError - lastIndexOf( x, 0, 0, null ); // $ExpectError - lastIndexOf( x, 0, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, 0, [] ); // $ExpectError - lastIndexOf( x, 0, 0, {} ); // $ExpectError - lastIndexOf( x, 0, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21774e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5, false ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5, false ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5, false ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3, false ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50, false ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 3a65918..898fca2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5cf298c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..545924f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index bf482d9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 45f41b1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,179 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3, false ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex, equalNaNs ) { - var i; - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( x[ i ] ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3, false ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex, equalNaNs ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - if ( equalNaNs && isnan( searchElement ) ) { - for ( i = fromIndex; i >= 0; i-- ) { - if ( isnan( get( data, i ) ) ) { - return i; - } - } - return -1; - } - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex, equalNaNs ); - } - return internal( x, searchElement, fromIndex, equalNaNs ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index cb3630c..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6a136e --- /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 0e2568d..0000000 --- a/test/test.js +++ /dev/null @@ -1,437 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like, equal_nans=false)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0, false ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2, false ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2, false ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5, false ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3, false ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1, false ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [], 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [], 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `false`, the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `equalNaNs` is `true`, the function supports finding an element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( [ 0 ], NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 0.0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 0 ] ), NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, 0, 'returns expected value' ); - - x = { - 'length': 1, - '0': 0 - }; - actual = lastIndexOf( x, NaN, 0, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - // Unequal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, false ); // eslint-disable-line max-len - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, false ); - t.strictEqual( actual, -1, 'returns expected value' ); - - // Equal NaNs... - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20, true ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 3a99d56d102a8a20c9d2dc0493ff64f1af633d73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 01:18:01 +0000 Subject: [PATCH 47/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a2a8756..e5a41ce 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.2", @@ -85,4 +86,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 24275afa0c391d15204a7f4dd73babe327229391 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 01:18:33 +0000 Subject: [PATCH 48/55] Remove files --- index.d.ts | 59 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4906 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 898fca2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, Complex64Array, Complex128Array } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @param equalNaNs - boolean indicating whether NaNs should be considered equal -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3, false ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5cf298c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";function e(e,n,s,f){var i;if(function(r,t){return"function"==typeof r[t]}(e,"lastIndexOf")&&!1===f)return e.lastIndexOf(n,s);if(s<0){if((s+=e.length)<0)return-1}else s>e.length&&(s=e.length-1);return(i=r(e)).accessorProtocol?function(r,e,n,s){var f,i,o;if(f=r.data,i=r.accessors[0],s&&t(e)){for(o=n;o>=0;o--)if(t(i(f,o)))return o;return-1}for(o=n;o>=0;o--)if(e===i(f,o))return o;return-1}(i,n,s,f):function(r,e,n,s){var f;if(s&&t(e)){for(f=n;f>=0;f--)if(t(r[f]))return f;return-1}for(f=n;f>=0;f--)if(e===r[f])return f;return-1}(e,n,s,f)}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 545924f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport isnan from '@stdlib/math-base-assert-is-nan';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3, false );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","equalNaNs","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","isnan","internal"],"mappings":";;wMA2JA,SAASA,EAAaC,EAAGC,EAAeC,EAAWC,GAClD,IAAIC,EACJ,GAjHD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA+GMC,CAAWN,EAAG,iBAAiC,IAAdG,EACrC,OAAOH,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEO,QACE,EAChB,OAAQ,OAEEL,EAAYF,EAAEO,SACzBL,EAAYF,EAAEO,OAAS,GAGxB,OADAH,EAAMI,EAAkBR,IACfS,iBApEV,SAAoBT,EAAGC,EAAeC,EAAWC,GAChD,IAAIO,EACAC,EACAC,EAKJ,GAHAF,EAAOV,EAAEU,KACTC,EAAMX,EAAEa,UAAW,GAEdV,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOH,EAAKD,EAAME,IACtB,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBU,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA+CSC,CAAWT,EAAKH,EAAeC,EAAWC,GA1GnD,SAAmBH,EAAGC,EAAeC,EAAWC,GAC/C,IAAIS,EACJ,GAAKT,GAAaW,EAAOb,GAAkB,CAC1C,IAAMW,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKE,EAAOd,EAAGY,IACd,OAAOA,EAGT,OAAQ,CACR,CACD,IAAMA,EAAIV,EAAWU,GAAK,EAAGA,IAC5B,GAAKX,IAAkBD,EAAGY,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4FQG,CAAUf,EAAGC,EAAeC,EAAWC,EAC/C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a6a136e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d1a1a5fcb6d91d556152f33816b4b5c97dd2e3c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 01:18:47 +0000 Subject: [PATCH 49/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 206 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 72 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 159 - package.json | 61 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 355 -- 43 files changed, 4864 insertions(+), 4493 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d0f3637..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -195,7 +186,7 @@ idx = lastIndexOf( x, 'foo', -50 ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a97490c..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1 ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 51640e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var s=c(function(O,u){ -var o=require('@stdlib/array-base-arraylike2object/dist');function f(r,t){return typeof r[t]=="function"}function l(r,t,e){var i;for(i=e;i>=0;i--)if(t===r[i])return i;return-1}function v(r,t,e){var i,n,a;for(i=r.data,n=r.accessors[0],a=e;a>=0;a--)if(t===n(i,a))return a;return-1}function g(r,t,e){var i;if(f(r,"lastIndexOf"))return r.lastIndexOf(t,e);if(e<0){if(e+=r.length,e<0)return-1}else e>r.length&&(e=r.length-1);return i=o(r),i.accessorProtocol?v(i,t,e):l(r,t,e)}u.exports=g -});var h=s();module.exports=h; -/** @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 e67e43c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAqBtE,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAiBA,SAASC,EAAUC,EAAGC,EAAeC,EAAY,CAChD,IAAI,EACJ,IAAM,EAAIA,EAAW,GAAK,EAAG,IAC5B,GAAKD,IAAkBD,EAAG,CAAE,EAC3B,OAAO,EAGT,MAAO,EACR,CAoBA,SAASG,EAAWH,EAAGC,EAAeC,EAAY,CACjD,IAAIE,EACAC,EACAC,EAKJ,IAHAF,EAAOJ,EAAE,KACTK,EAAML,EAAE,UAAW,CAAE,EAEfM,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBI,EAAKD,EAAME,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CA+BA,SAASC,EAAaP,EAAGC,EAAeC,EAAY,CACnD,IAAIL,EACJ,GAAKD,EAAWI,EAAG,aAAc,EAChC,OAAOA,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAGxB,OADAH,EAAMF,EAAkBK,CAAE,EACrBH,EAAI,iBACDM,EAAWN,EAAKI,EAAeC,CAAU,EAE1CH,EAAUC,EAAGC,EAAeC,CAAU,CAC9C,CAKAR,EAAO,QAAUa,IC1HjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "accessors", "data", "get", "i", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8c10143..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method, the function - defers execution to that method and assumes that the method has the - following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method, the - function performs a linear scan and returns immediately upon finding a - match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3 ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b0dfabd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3 ); // $ExpectError - lastIndexOf( true, 0, 3 ); // $ExpectError - lastIndexOf( false, 0, 3 ); // $ExpectError - lastIndexOf( null, 0, 3 ); // $ExpectError - lastIndexOf( void 0, 0, 3 ); // $ExpectError - lastIndexOf( {}, 0, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, true ); // $ExpectError - lastIndexOf( x, 0, false ); // $ExpectError - lastIndexOf( x, 0, null ); // $ExpectError - lastIndexOf( x, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, [] ); // $ExpectError - lastIndexOf( x, 0, {} ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21d50b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5 ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5 ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5 ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3 ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50 ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 088c8a6..d7d2a10 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dee648a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";function t(t,e,n){var f;if(function(r,t){return"function"==typeof r[t]}(t,"lastIndexOf"))return t.lastIndexOf(e,n);if(n<0){if((n+=t.length)<0)return-1}else n>t.length&&(n=t.length-1);return(f=r(t)).accessorProtocol?function(r,t,e){var n,f,o;for(n=r.data,f=r.accessors[0],o=e;o>=0;o--)if(t===f(n,o))return o;return-1}(f,e,n):function(r,t,e){var n;for(n=e;n>=0;n--)if(t===r[n])return n;return-1}(t,e,n)}export{t as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f976a3f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","internal"],"mappings":";;sGAuIA,SAASA,EAAaC,EAAGC,EAAeC,GACvC,IAAIC,EACJ,GA9FD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA4FMC,CAAWL,EAAG,eAClB,OAAOA,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEM,QACE,EAChB,OAAQ,OAEEJ,EAAYF,EAAEM,SACzBJ,EAAYF,EAAEM,OAAS,GAGxB,OADAH,EAAMI,EAAkBP,IACfQ,iBA3DV,SAAoBR,EAAGC,EAAeC,GACrC,IAAIO,EACAC,EACAC,EAKJ,IAHAF,EAAOT,EAAES,KACTC,EAAMV,EAAEY,UAAW,GAEbD,EAAIT,EAAWS,GAAK,EAAGA,IAC5B,GAAKV,IAAkBS,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA8CSC,CAAWT,EAAKF,EAAeC,GAxFxC,SAAmBF,EAAGC,EAAeC,GACpC,IAAIS,EACJ,IAAMA,EAAIT,EAAWS,GAAK,EAAGA,IAC5B,GAAKV,IAAkBD,EAAGW,GACzB,OAAOA,EAGT,OAAQ,CACT,CAkFQE,CAAUb,EAAGC,EAAeC,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e198baf..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 06435a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3 ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex ) { - var i; - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* -* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); -* -* var idx = accessors( x, 2, 3 ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex ) { - var data; - var get; - var i; - - data = x.data; - get = x.accessors[ 0 ]; - - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( data, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex ) { - var obj; - if ( hasMethod( x, 'lastIndexOf' ) ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - obj = arraylike2object( x ); - if ( obj.accessorProtocol ) { - return accessors( obj, searchElement, fromIndex ); - } - return internal( x, searchElement, fromIndex ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index e5a41ce..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..295c0a3 --- /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 d064584..0000000 --- a/test/test.js +++ /dev/null @@ -1,355 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [], 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 730ba746115bf058a07bb8db0b0d85c64ddedb55 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 04:40:25 +0000 Subject: [PATCH 50/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1b71244..1cf13e7 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-resolve-getter": "^0.2.2", "@stdlib/assert-is-accessor-array": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.2", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c7df6221a920164f3d9c40ac2cc0698b4162856f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 04:40:49 +0000 Subject: [PATCH 51/55] Remove files --- index.d.ts | 58 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4905 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 d7d2a10..0000000 --- a/index.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | AccessorArrayLike, searchElement: unknown, fromIndex: number ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dee648a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";function t(t,e,n){var f;if(function(r,t){return"function"==typeof r[t]}(t,"lastIndexOf"))return t.lastIndexOf(e,n);if(n<0){if((n+=t.length)<0)return-1}else n>t.length&&(n=t.length-1);return(f=r(t)).accessorProtocol?function(r,t,e){var n,f,o;for(n=r.data,f=r.accessors[0],o=e;o>=0;o--)if(t===f(n,o))return o;return-1}(f,e,n):function(r,t,e){var n;for(n=e;n>=0;n--)if(t===r[n])return n;return-1}(t,e,n)}export{t as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f976a3f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( data, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tvar obj;\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","obj","method","hasMethod","length","arraylike2object","accessorProtocol","data","get","i","accessors","internal"],"mappings":";;sGAuIA,SAASA,EAAaC,EAAGC,EAAeC,GACvC,IAAIC,EACJ,GA9FD,SAAoBA,EAAKC,GACxB,MAAkC,mBAAlBD,EAAKC,EACtB,CA4FMC,CAAWL,EAAG,eAClB,OAAOA,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEM,QACE,EAChB,OAAQ,OAEEJ,EAAYF,EAAEM,SACzBJ,EAAYF,EAAEM,OAAS,GAGxB,OADAH,EAAMI,EAAkBP,IACfQ,iBA3DV,SAAoBR,EAAGC,EAAeC,GACrC,IAAIO,EACAC,EACAC,EAKJ,IAHAF,EAAOT,EAAES,KACTC,EAAMV,EAAEY,UAAW,GAEbD,EAAIT,EAAWS,GAAK,EAAGA,IAC5B,GAAKV,IAAkBS,EAAKD,EAAME,GACjC,OAAOA,EAGT,OAAQ,CACT,CA8CSC,CAAWT,EAAKF,EAAeC,GAxFxC,SAAmBF,EAAGC,EAAeC,GACpC,IAAIS,EACJ,IAAMA,EAAIT,EAAWS,GAAK,EAAGA,IAC5B,GAAKV,IAAkBD,EAAGW,GACzB,OAAOA,EAGT,OAAQ,CACT,CAkFQE,CAAUb,EAAGC,EAAeC,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 295c0a3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0ec3d972f403ce4345ccfac91d2fc69ab98fb218 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Mar 2025 04:41:07 +0000 Subject: [PATCH 52/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 207 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 72 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 154 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 355 -- 43 files changed, 4864 insertions(+), 4490 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.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d0f3637..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -195,7 +186,7 @@ idx = lastIndexOf( x, 'foo', -50 ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a97490c..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1 ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 12cc07b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var a=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var s=a(function(q,u){ -var f=require('@stdlib/assert-is-accessor-array/dist'),c=require('@stdlib/array-base-resolve-getter/dist');function l(r,t){return typeof r[t]=="function"}function o(r,t,e){var i;for(i=e;i>=0;i--)if(t===r[i])return i;return-1}function v(r,t,e){var i,n;for(i=c(r),n=e;n>=0;n--)if(t===i(r,n))return n;return-1}function g(r,t,e){if(l(r,"lastIndexOf"))return r.lastIndexOf(t,e);if(e<0){if(e+=r.length,e<0)return-1}else e>r.length&&(e=r.length-1);return f(r)?v(r,t,e):o(r,t,e)}u.exports=g -});var h=s();module.exports=h; -/** @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 7fca7a7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/assert-is-accessor-array' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAgB,QAAS,mCAAoC,EAqBjE,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAiBA,SAASC,EAAUC,EAAGC,EAAeC,EAAY,CAChD,IAAI,EACJ,IAAM,EAAIA,EAAW,GAAK,EAAG,IAC5B,GAAKD,IAAkBD,EAAG,CAAE,EAC3B,OAAO,EAGT,MAAO,EACR,CAmBA,SAASG,EAAWH,EAAGC,EAAeC,EAAY,CACjD,IAAIE,EACAC,EAGJ,IADAD,EAAMT,EAAeK,CAAE,EACjBK,EAAIH,EAAWG,GAAK,EAAGA,IAC5B,GAAKJ,IAAkBG,EAAKJ,EAAGK,CAAE,EAChC,OAAOA,EAGT,MAAO,EACR,CA+BA,SAASC,EAAaN,EAAGC,EAAeC,EAAY,CACnD,GAAKN,EAAWI,EAAG,aAAc,EAChC,OAAOA,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAExB,OAAKN,EAAiBM,CAAE,EAChBG,EAAWH,EAAGC,EAAeC,CAAU,EAExCH,EAAUC,EAAGC,EAAeC,CAAU,CAC9C,CAKAT,EAAO,QAAUa,ICrHjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "resolveGetter", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "accessors", "get", "i", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8c10143..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method, the function - defers execution to that method and assumes that the method has the - following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method, the - function performs a linear scan and returns immediately upon finding a - match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3 ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b0dfabd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3 ); // $ExpectError - lastIndexOf( true, 0, 3 ); // $ExpectError - lastIndexOf( false, 0, 3 ); // $ExpectError - lastIndexOf( null, 0, 3 ); // $ExpectError - lastIndexOf( void 0, 0, 3 ); // $ExpectError - lastIndexOf( {}, 0, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, true ); // $ExpectError - lastIndexOf( x, 0, false ); // $ExpectError - lastIndexOf( x, 0, null ); // $ExpectError - lastIndexOf( x, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, [] ); // $ExpectError - lastIndexOf( x, 0, {} ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21d50b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5 ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5 ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5 ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3 ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50 ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 088c8a6..d7d2a10 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..adc5abb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";function t(t,n,s){if("function"==typeof t["lastIndexOf"])return t.lastIndexOf(n,s);if(s<0){if((s+=t.length)<0)return-1}else s>t.length&&(s=t.length-1);return r(t)?function(r,t,n){var s,i;for(s=e(r),i=n;i>=0;i--)if(t===s(r,i))return i;return-1}(t,n,s):function(r,e,t){var n;for(n=t;n>=0;n--)if(e===r[n])return n;return-1}(t,n,s)}export{t as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..601823e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/assert-is-accessor-array';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","length","isAccessorArray","get","i","resolveGetter","accessors","internal"],"mappings":";;uMAoIA,SAASA,EAAaC,EAAGC,EAAeC,GACvC,GAxFkC,mBAwFlBF,EAAG,eAClB,OAAOA,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEG,QACE,EAChB,OAAQ,OAEED,EAAYF,EAAEG,SACzBD,EAAYF,EAAEG,OAAS,GAExB,OAAKC,EAAiBJ,GAtDvB,SAAoBA,EAAGC,EAAeC,GACrC,IAAIG,EACAC,EAGJ,IADAD,EAAME,EAAeP,GACfM,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBI,EAAKL,EAAGM,GAC9B,OAAOA,EAGT,OAAQ,CACT,CA4CSE,CAAWR,EAAGC,EAAeC,GAlFtC,SAAmBF,EAAGC,EAAeC,GACpC,IAAII,EACJ,IAAMA,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBD,EAAGM,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4EQG,CAAUT,EAAGC,EAAeC,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e198baf..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 67fa4d1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,154 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/assert-is-accessor-array' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3 ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex ) { - var i; - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var idx = accessors( x, 2, 3 ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex ) { - var get; - var i; - - get = resolveGetter( x ); - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( x, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex ) { - if ( hasMethod( x, 'lastIndexOf' ) ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - if ( isAccessorArray( x ) ) { - return accessors( x, searchElement, fromIndex ); - } - return internal( x, searchElement, fromIndex ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 1cf13e7..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/assert-is-accessor-array": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe0c170 --- /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 d064584..0000000 --- a/test/test.js +++ /dev/null @@ -1,355 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [], 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); From 672d128fe92e28010790e72f3af41f4637ebe465 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 01:20:24 +0000 Subject: [PATCH 53/55] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1b71244..1cf13e7 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/array-base-resolve-getter": "^0.2.2", "@stdlib/assert-is-accessor-array": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-base-accessor": "^0.2.2", @@ -86,4 +87,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5a42ab640b46b9e33caeeb4775a2fca2fee3d6da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 01:33:55 +0000 Subject: [PATCH 54/55] Remove files --- index.d.ts | 58 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4905 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 d7d2a10..0000000 --- a/index.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 } from '@stdlib/types/array'; - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - The function scans an input array from the starting index to the beginning of the array (i.e., backward). -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`. -* -* @param x - input array -* @param searchElement - search element -* @param fromIndex - starting index (inclusive) -* @returns index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ -declare function lastIndexOf( x: Collection | AccessorArrayLike, searchElement: unknown, fromIndex: number ): number; - - -// EXPORTS // - -export = lastIndexOf; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index adc5abb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";function t(t,n,s){if("function"==typeof t["lastIndexOf"])return t.lastIndexOf(n,s);if(s<0){if((s+=t.length)<0)return-1}else s>t.length&&(s=t.length-1);return r(t)?function(r,t,n){var s,i;for(s=e(r),i=n;i>=0;i--)if(t===s(r,i))return i;return-1}(t,n,s):function(r,e,t){var n;for(n=t;n>=0;n--)if(e===r[n])return n;return-1}(t,n,s)}export{t as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 601823e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/assert-is-accessor-array';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","length","isAccessorArray","get","i","resolveGetter","accessors","internal"],"mappings":";;uMAoIA,SAASA,EAAaC,EAAGC,EAAeC,GACvC,GAxFkC,mBAwFlBF,EAAG,eAClB,OAAOA,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEG,QACE,EAChB,OAAQ,OAEED,EAAYF,EAAEG,SACzBD,EAAYF,EAAEG,OAAS,GAExB,OAAKC,EAAiBJ,GAtDvB,SAAoBA,EAAGC,EAAeC,GACrC,IAAIG,EACAC,EAGJ,IADAD,EAAME,EAAeP,GACfM,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBI,EAAKL,EAAGM,GAC9B,OAAOA,EAGT,OAAQ,CACT,CA4CSE,CAAWR,EAAGC,EAAeC,GAlFtC,SAAmBF,EAAGC,EAAeC,GACpC,IAAII,EACJ,IAAMA,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBD,EAAGM,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4EQG,CAAUT,EAAGC,EAAeC,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fe0c170..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 36316c345d3bc26451f2d1fba69042ef93dc1dd1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 01:34:10 +0000 Subject: [PATCH 55/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 162 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.length.js | 96 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 72 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 42 - lib/main.js | 154 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 355 -- 44 files changed, 4864 insertions(+), 4446 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.length.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dfa9bf0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-23T01:13:22.623Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d0f3637..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8eacb09..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of) 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 c47f7df..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: '34 22 * * 1' - - # 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 + + ```
@@ -195,7 +186,7 @@ idx = lastIndexOf( x, 'foo', -50 ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a97490c..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var lastIndexOf = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeroTo( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = lastIndexOf( x, -2, len-1 ); - if ( out !== out ) { - b.fail( 'should return an integer' ); - } - } - b.toc(); - if ( !isInteger( out ) || out >= 0 ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ac86123..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of" -%% click B href "https://github.com/stdlib-js/array-base-last-index-of/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-last-index-of/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-last-index-of/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-last-index-of/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-last-index-of/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/last-index-of -[production-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-last-index-of/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-last-index-of/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-last-index-of/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 a39b838..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import lastIndexOf from '../docs/types/index'; -export = lastIndexOf; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 12cc07b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var a=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var s=a(function(q,u){ -var f=require('@stdlib/assert-is-accessor-array/dist'),c=require('@stdlib/array-base-resolve-getter/dist');function l(r,t){return typeof r[t]=="function"}function o(r,t,e){var i;for(i=e;i>=0;i--)if(t===r[i])return i;return-1}function v(r,t,e){var i,n;for(i=c(r),n=e;n>=0;n--)if(t===i(r,n))return n;return-1}function g(r,t,e){if(l(r,"lastIndexOf"))return r.lastIndexOf(t,e);if(e<0){if(e+=r.length,e<0)return-1}else e>r.length&&(e=r.length-1);return f(r)?v(r,t,e):o(r,t,e)}u.exports=g -});var h=s();module.exports=h; -/** @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 7fca7a7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/assert-is-accessor-array' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAgB,QAAS,mCAAoC,EAqBjE,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAiBA,SAASC,EAAUC,EAAGC,EAAeC,EAAY,CAChD,IAAI,EACJ,IAAM,EAAIA,EAAW,GAAK,EAAG,IAC5B,GAAKD,IAAkBD,EAAG,CAAE,EAC3B,OAAO,EAGT,MAAO,EACR,CAmBA,SAASG,EAAWH,EAAGC,EAAeC,EAAY,CACjD,IAAIE,EACAC,EAGJ,IADAD,EAAMT,EAAeK,CAAE,EACjBK,EAAIH,EAAWG,GAAK,EAAGA,IAC5B,GAAKJ,IAAkBG,EAAKJ,EAAGK,CAAE,EAChC,OAAOA,EAGT,MAAO,EACR,CA+BA,SAASC,EAAaN,EAAGC,EAAeC,EAAY,CACnD,GAAKN,EAAWI,EAAG,aAAc,EAChC,OAAOA,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAExB,OAAKN,EAAiBM,CAAE,EAChBG,EAAWH,EAAGC,EAAeC,CAAU,EAExCH,EAAUC,EAAGC,EAAeC,CAAU,CAC9C,CAKAT,EAAO,QAAUa,ICrHjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "resolveGetter", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "accessors", "get", "i", "lastIndexOf", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8c10143..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, searchElement, fromIndex ) - Returns the index of the last element which equals a provided search - element. - - If provided an array-like object having a `lastIndexOf` method, the function - defers execution to that method and assumes that the method has the - following signature: - - x.lastIndexOf( searchElement, fromIndex ) - - If provided an array-like object without a `lastIndexOf` method, the - function performs a linear scan and returns immediately upon finding a - match. - - If unable to find an element which equals a provided search element, the - function returns -1. - - The function scans an input array from the starting index to the beginning - of the array (i.e., backward). - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - searchElement: any - Search element. - - fromIndex: integer - Starting index (inclusive). If less than zero, the starting index is - resolved relative to the last array element, with the last array element - corresponding to `fromIndex = -1`. - - Returns - ------- - out: integer - Index or -1. - - Examples - -------- - > var out = {{alias}}( [ 1, 3, 3, 4 ], 3, 3 ) - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b0dfabd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import lastIndexOf = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - lastIndexOf( [ 1, 2, 3 ], 0, 3 ); // $ExpectType number - lastIndexOf( new Float64Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Float32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Int8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint32Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint16Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8Array( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Uint8ClampedArray( [ 1, 2, 3 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number - lastIndexOf( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), 0, 3 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - lastIndexOf( 5, 0, 3 ); // $ExpectError - lastIndexOf( true, 0, 3 ); // $ExpectError - lastIndexOf( false, 0, 3 ); // $ExpectError - lastIndexOf( null, 0, 3 ); // $ExpectError - lastIndexOf( void 0, 0, 3 ); // $ExpectError - lastIndexOf( {}, 0, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = [ 1, 2, 3 ]; - - lastIndexOf( x, 0, '5' ); // $ExpectError - lastIndexOf( x, 0, true ); // $ExpectError - lastIndexOf( x, 0, false ); // $ExpectError - lastIndexOf( x, 0, null ); // $ExpectError - lastIndexOf( x, 0, void 0 ); // $ExpectError - lastIndexOf( x, 0, [] ); // $ExpectError - lastIndexOf( x, 0, {} ); // $ExpectError - lastIndexOf( x, 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - lastIndexOf(); // $ExpectError - lastIndexOf( [ 1, 2, 3 ] ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0 ); // $ExpectError - lastIndexOf( [ 1, 2, 3 ], 0, 3, false ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a21d50b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 lastIndexOf = require( './../lib' ); - -var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ]; - -var idx = lastIndexOf( x, 'beep', 5 ); -console.log( idx ); -// => 2 - -idx = lastIndexOf( x, 'bop', 5 ); -console.log( idx ); -// => -1 - -idx = lastIndexOf( x, 'foo', 5 ); -console.log( idx ); -// => 4 - -idx = lastIndexOf( x, 'foo', -3 ); -console.log( idx ); -// => 0 - -idx = lastIndexOf( x, 'foo', -50 ); -console.log( idx ); -// => -1 diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 088c8a6..d7d2a10 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..adc5abb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";function t(t,n,s){if("function"==typeof t["lastIndexOf"])return t.lastIndexOf(n,s);if(s<0){if((s+=t.length)<0)return-1}else s>t.length&&(s=t.length-1);return r(t)?function(r,t,n){var s,i;for(s=e(r),i=n;i>=0;i--)if(t===s(r,i))return i;return-1}(t,n,s):function(r,e,t){var n;for(n=t;n>=0;n--)if(e===r[n])return n;return-1}(t,n,s)}export{t as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..601823e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/assert-is-accessor-array';\nimport resolveGetter from '@stdlib/array-base-resolve-getter';\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* import toAccessorArray from '@stdlib/array-base-to-accessor-array';\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* import Int32Array from '@stdlib/array-int32';\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nexport default lastIndexOf;\n"],"names":["lastIndexOf","x","searchElement","fromIndex","length","isAccessorArray","get","i","resolveGetter","accessors","internal"],"mappings":";;uMAoIA,SAASA,EAAaC,EAAGC,EAAeC,GACvC,GAxFkC,mBAwFlBF,EAAG,eAClB,OAAOA,EAAED,YAAaE,EAAeC,GAEtC,GAAKA,EAAY,GAEhB,IADAA,GAAaF,EAAEG,QACE,EAChB,OAAQ,OAEED,EAAYF,EAAEG,SACzBD,EAAYF,EAAEG,OAAS,GAExB,OAAKC,EAAiBJ,GAtDvB,SAAoBA,EAAGC,EAAeC,GACrC,IAAIG,EACAC,EAGJ,IADAD,EAAME,EAAeP,GACfM,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBI,EAAKL,EAAGM,GAC9B,OAAOA,EAGT,OAAQ,CACT,CA4CSE,CAAWR,EAAGC,EAAeC,GAlFtC,SAAmBF,EAAGC,EAAeC,GACpC,IAAII,EACJ,IAAMA,EAAIJ,EAAWI,GAAK,EAAGA,IAC5B,GAAKL,IAAkBD,EAAGM,GACzB,OAAOA,EAGT,OAAQ,CACT,CA4EQG,CAAUT,EAAGC,EAAeC,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e198baf..0000000 --- a/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the index of the last element which equals a provided search element. -* -* @module @stdlib/array-base-last-index-of -* -* @example -* var lastIndexOf = require( '@stdlib/array-base-last-index-of' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 67fa4d1..0000000 --- a/lib/main.js +++ /dev/null @@ -1,154 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/assert-is-accessor-array' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); - - -// FUNCTIONS // - -/** -* Tests whether an object has a specified method. -* -* @private -* @param {Object} obj - input object -* @param {string} method - method name -* @returns {boolean} boolean indicating whether an object has a specified method -* -* @example -* var bool = hasMethod( [], 'lastIndexOf' ); -* // returns true -* -* @example -* var bool = hasMethod( [], 'beep' ); -* // returns false -*/ -function hasMethod( obj, method ) { - return ( typeof obj[ method ] === 'function' ); -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = internal( x, 2, 3 ); -* // returns 1 -*/ -function internal( x, searchElement, fromIndex ) { - var i; - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === x[ i ] ) { - return i; - } - } - return -1; -} - -/** -* Returns the index of the last element which equals a provided search element. -* -* @private -* @param {Object} x - input array object -* @param {*} searchElement - search element -* @param {NonNegativeInteger} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var idx = accessors( x, 2, 3 ); -* // returns 1 -*/ -function accessors( x, searchElement, fromIndex ) { - var get; - var i; - - get = resolveGetter( x ); - for ( i = fromIndex; i >= 0; i-- ) { - if ( searchElement === get( x, i ) ) { - return i; - } - } - return -1; -} - - -// MAIN // - -/** -* Returns the index of the last element which equals a provided search element. -* -* ## Notes -* -* - If unable to find an element which equals a provided search element, the function returns `-1`. -* -* @param {Collection} x - input array -* @param {*} searchElement - search element -* @param {integer} fromIndex - starting index (inclusive) -* @returns {integer} index -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var idx = lastIndexOf( x, 2, 3 ); -* // returns 1 -*/ -function lastIndexOf( x, searchElement, fromIndex ) { - if ( hasMethod( x, 'lastIndexOf' ) ) { - return x.lastIndexOf( searchElement, fromIndex ); - } - if ( fromIndex < 0 ) { - fromIndex += x.length; - if ( fromIndex < 0 ) { - return -1; - } - } else if ( fromIndex > x.length ) { - fromIndex = x.length - 1; - } - if ( isAccessorArray( x ) ) { - return accessors( x, searchElement, fromIndex ); - } - return internal( x, searchElement, fromIndex ); -} - - -// EXPORTS // - -module.exports = lastIndexOf; diff --git a/package.json b/package.json index 1cf13e7..e77918e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return the index of the last element which equals a provided search element.", "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,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/assert-is-accessor-array": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-accessor": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -87,4 +31,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe0c170 --- /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 d064584..0000000 --- a/test/test.js +++ /dev/null @@ -1,355 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 AccessorArray = require( '@stdlib/array-base-accessor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var lastIndexOf = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof lastIndexOf, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (generic)', function test( t ) { - var actual; - var x; - - x = [ 1, 1, 2, 2, 3, 3 ]; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (float64)', function test( t ) { - var actual; - var x; - - x = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - - actual = lastIndexOf( x, 1.0, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1.0, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1.0, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1.0, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2.0, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3.0, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (int32)', function test( t ) { - var actual; - var x; - - x = new Int32Array( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (accessors)', function test( t ) { - var actual; - var x; - - x = new AccessorArray( [ 1, 1, 2, 2, 3, 3 ] ); - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns the last index of an element which equals a provided search element (array-like)', function test( t ) { - var actual; - var x; - - x = { - 'length': 6, - '0': 1, - '1': 1, - '2': 2, - '3': 2, - '4': 3, - '5': 3 - }; - - actual = lastIndexOf( x, 1, 5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 5 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 5 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Nonnegative starting index... - actual = lastIndexOf( x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = lastIndexOf( x, 2, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 4 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 3, 100 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - // Negative starting index... - actual = lastIndexOf( x, 1, -1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -2 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = lastIndexOf( x, 1, -5 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = lastIndexOf( x, 2, -3 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - actual = lastIndexOf( x, 3, -1 ); - t.strictEqual( actual, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided an empty array', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [], 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [] ), 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0 - }; - actual = lastIndexOf( x, 0, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ NaN ], NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ NaN ] ), NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 1, - '0': NaN - }; - actual = lastIndexOf( x, NaN, 0 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `-1` if provided a starting index which exceeds the minimum array index', function test( t ) { - var actual; - var x; - - actual = lastIndexOf( [ 1, 2, 3 ], 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new Int32Array( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - actual = lastIndexOf( new AccessorArray( [ 1, 2, 3 ] ), 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - x = { - 'length': 0, - '0': 1, - '1': 2, - '2': 3 - }; - actual = lastIndexOf( x, 0, -20 ); - t.strictEqual( actual, -1, 'returns expected value' ); - - t.end(); -});