From 0217cd316af0df7c712f94de5c31bb276a344312 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 9 Apr 2024 15:08:51 +0000 Subject: [PATCH 01/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index b753f56..67d633e 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From d7971ea48eca8b36588181ab372c6342ee3d9bca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 9 Apr 2024 15:09:49 +0000 Subject: [PATCH 02/42] 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 | 1012 ----- .github/workflows/publish.yml | 249 -- .github/workflows/publish_cli.yml | 176 - .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 | 127 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 48 files changed, 4861 insertions(+), 5367 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 c4033da..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 df867aa..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1012 +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 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 + + ```
-
- @@ -262,7 +159,7 @@ p ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0779103..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('null3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('null3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('null3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('null2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('nullE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 bc389c0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's';\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d6350e2 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7dcb11d --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;64BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 198e4c1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's'; -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index 67d633e..b27203b 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-regexp-string": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/cli-ctor": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/process-read-stdin": "^0.2.1", - "@stdlib/regexp-eol": "^0.2.1", - "@stdlib/streams-node-stdin": "^0.2.1", - "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", - "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", - "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-regexp-from-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.1", - "@stdlib/assert-is-windows": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.1", - "@stdlib/string-replace": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..036373c --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 497d9eb7316e173d4107613ef3675a7317b39fad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:58:14 +0000 Subject: [PATCH 03/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index b753f56..67d633e 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From b7d70ce1351111e5ff7ee2e17460f7541a41286e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:28:20 +0000 Subject: [PATCH 04/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 4582fa0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d6350e2..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7dcb11d..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;64BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 036373c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4f2b7286541fedd02aa28ee658a88b812fda87f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:28:42 +0000 Subject: [PATCH 05/42] 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 | 1012 ----- .github/workflows/publish.yml | 249 -- .github/workflows/publish_cli.yml | 176 - .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 | 127 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 48 files changed, 4861 insertions(+), 5369 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 c4033da..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 df867aa..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1012 +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 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 + + ```
-
- @@ -262,7 +159,7 @@ p ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0779103..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('null3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('null3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('null3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('null2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('nullE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 bc389c0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's';\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d6350e2 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7dcb11d --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;64BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 198e4c1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's'; -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index 67d633e..b27203b 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-regexp-string": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/cli-ctor": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/process-read-stdin": "^0.2.1", - "@stdlib/regexp-eol": "^0.2.1", - "@stdlib/streams-node-stdin": "^0.2.1", - "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", - "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", - "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-regexp-from-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.1", - "@stdlib/assert-is-windows": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.1", - "@stdlib/string-replace": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..036373c --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 27a0966cc8461670e2d41e030ef5867f14ca7842 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 13 Apr 2024 01:55:16 +0000 Subject: [PATCH 06/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 15955cc..aab5bdf 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 4fbc49c59deaf2776937ef4ca3e27032f87c0385 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 13 Apr 2024 02:20:30 +0000 Subject: [PATCH 07/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 4582fa0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d6350e2..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7dcb11d..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;64BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 036373c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 775fb818e6effa77a7814e1133a8f4fb09735bdb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 13 Apr 2024 02:20:53 +0000 Subject: [PATCH 08/42] 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 | 1008 ----- .github/workflows/publish.yml | 248 -- .github/workflows/publish_cli.yml | 175 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 127 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 48 files changed, 4861 insertions(+), 5357 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 c4033da..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 15fd596..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -262,7 +159,7 @@ p ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0779103..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('null3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('null3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('null3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('null2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('nullE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 bc389c0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's';\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d6350e2 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7dcb11d --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;64BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 198e4c1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's'; -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index aab5bdf..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-regexp-string": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/cli-ctor": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/process-read-stdin": "^0.2.1", - "@stdlib/regexp-eol": "^0.2.1", - "@stdlib/streams-node-stdin": "^0.2.1", - "@stdlib/string-base-last": "github:stdlib-js/string-base-last#main", - "@stdlib/string-base-last-code-point": "github:stdlib-js/string-base-last-code-point#main", - "@stdlib/string-base-last-grapheme-cluster": "github:stdlib-js/string-base-last-grapheme-cluster#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-regexp-from-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.1", - "@stdlib/assert-is-windows": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.1", - "@stdlib/string-replace": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..036373c --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From bd2e8783ab6417673cc28139a114cb0ea3295b0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 13 Apr 2024 02:25:03 +0000 Subject: [PATCH 09/42] 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 ba0c1df..2f1d4e6 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import last from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-last@esm/index.mjs'; +import last from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-last@v0.1.0-esm/index.mjs'; ``` #### last( str\[, n]\[, options] ) @@ -105,7 +105,7 @@ out = last( 'foo bar', 10 ); - - - - From bfa3325c1842b7bcd73520c3745b206edbf7b14a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Apr 2024 02:53:16 +0000 Subject: [PATCH 13/42] 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 | 1008 ----- .github/workflows/publish.yml | 248 -- .github/workflows/publish_cli.yml | 175 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 127 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 48 files changed, 4861 insertions(+), 5374 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 c4033da..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 15fd596..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -261,7 +158,7 @@ p ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0779103..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('null3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('null3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('null3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('null2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('nullE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 bc389c0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's';\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..592c8d9 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 198e4c1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's'; -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index 08ea4fe..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-regexp-string": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/cli-ctor": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/process-read-stdin": "^0.2.1", - "@stdlib/regexp-eol": "^0.2.1", - "@stdlib/streams-node-stdin": "^0.2.1", - "@stdlib/string-base-last": "^0.1.0", - "@stdlib/string-base-last-code-point": "^0.1.0", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-regexp-from-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.1", - "@stdlib/assert-is-windows": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.1", - "@stdlib/string-replace": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b7b01b0 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From e6b9c9df6beb8798ce688bf3a60dc31a6090e88c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 26 Dec 2024 07:41:47 +0000 Subject: [PATCH 14/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 3fa63d7..f36d4f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.1", "@stdlib/string-base-last-code-point": "^0.1.1", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 55e1f6e0657c0f30af952f10fa03839ead0e8747 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 26 Dec 2024 07:47:22 +0000 Subject: [PATCH 15/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 4582fa0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 592c8d9..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7b01b0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3399fe11f636fb5eae8c9c7e973e7fcfedbbfb21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 26 Dec 2024 07:47:42 +0000 Subject: [PATCH 16/42] 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 | 1008 ---- .github/workflows/publish.yml | 252 - .github/workflows/publish_cli.yml | 175 - .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 | 83 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 49 files changed, 4862 insertions(+), 5564 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c4033da..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 663474a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 bc389c0..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's';\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..82a0866 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 198e4c1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's'; -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index f36d4f1..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-last": "^0.1.1", - "@stdlib/string-base-last-code-point": "^0.1.1", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48ebef1 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From ab0b05617bb5564744b28eb895146703782eb3d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 25 Aug 2025 03:00:34 +0000 Subject: [PATCH 17/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 3fa63d7..f36d4f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.1", "@stdlib/string-base-last-code-point": "^0.1.1", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d93a45144add5284d73aeb31e203dfef2a28bbf9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 25 Aug 2025 03:04:55 +0000 Subject: [PATCH 18/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 4582fa0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 82a0866..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48ebef1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df15d4a8002e29c52545e10598bd37e93ceca488 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 25 Aug 2025 03:05:15 +0000 Subject: [PATCH 19/42] 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 | 1008 ---- .github/workflows/publish.yml | 252 - .github/workflows/publish_cli.yml | 175 - .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 | 85 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 49 files changed, 4862 insertions(+), 5569 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 663474a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5d4b934 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index f36d4f1..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-last": "^0.1.1", - "@stdlib/string-base-last-code-point": "^0.1.1", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48ebef1 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 83723b8d0a97948699ff3da223ffaa6d3ef6ee60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Sep 2025 05:24:11 +0000 Subject: [PATCH 20/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 3fa63d7..f36d4f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.1", "@stdlib/string-base-last-code-point": "^0.1.1", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From fec88f0a80dc75aef79e55c5aafa4690c45c6b7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Sep 2025 05:28:39 +0000 Subject: [PATCH 21/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 4582fa0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5d4b934..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48ebef1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 41699795894b279e68a9f0a882492854529cf55f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 6 Sep 2025 05:28:58 +0000 Subject: [PATCH 22/42] 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 | 1008 ---- .github/workflows/publish.yml | 252 - .github/workflows/publish_cli.yml | 175 - .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 | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 49 files changed, 4862 insertions(+), 5570 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 663474a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5d4b934 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index f36d4f1..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-last": "^0.1.1", - "@stdlib/string-base-last-code-point": "^0.1.1", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48ebef1 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 1fed89d152a6a32bb47986355a486ee547956936 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Sep 2025 00:36:27 +0000 Subject: [PATCH 23/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 3fa63d7..f36d4f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.1", "@stdlib/string-base-last-code-point": "^0.1.1", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From f283b244bf430390d8c6016ed7d6860cbc09665d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Sep 2025 00:39:53 +0000 Subject: [PATCH 24/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 72f5baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5d4b934..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48ebef1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 50f11d444d6387801afb112b4b3d3c5affeb16ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Sep 2025 00:40:16 +0000 Subject: [PATCH 25/42] 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 | 1008 ---- .github/workflows/publish.yml | 252 - .github/workflows/publish_cli.yml | 175 - .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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 50 files changed, 4862 insertions(+), 5576 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 8761182..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-09-08T00:34:52.826Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 663474a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5d4b934 --- /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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index f36d4f1..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-last": "^0.1.1", - "@stdlib/string-base-last-code-point": "^0.1.1", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48ebef1 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From b7af71579ddedb32c6f2c4c8a4633914ad6ef237 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 02:51:04 +0000 Subject: [PATCH 26/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 3fa63d7..f36d4f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.1", "@stdlib/string-base-last-code-point": "^0.1.1", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 97682342068d15f4cc8b80b5c53d3fa41a8aec69 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 04:34:37 +0000 Subject: [PATCH 27/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 72f5baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5d4b934..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{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48ebef1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e775459fad40d43eb71880b051a7fa3187c200cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 04:34:59 +0000 Subject: [PATCH 28/42] 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 | 1044 ---- .github/workflows/publish.yml | 261 - .github/workflows/publish_cli.yml | 184 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 49 files changed, 4862 insertions(+), 5693 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..29969d0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index f36d4f1..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-last": "^0.1.1", - "@stdlib/string-base-last-code-point": "^0.1.1", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48ebef1 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 519a012c7af1205432b3374d5bcf5acbb86be3df Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 03:11:05 +0000 Subject: [PATCH 29/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index c6fbb6b..4f5887c 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.2", "@stdlib/string-base-last-code-point": "^0.1.2", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 376343f8617fe1d3823a2a8d14bd7dbbea5934b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 04:22:29 +0000 Subject: [PATCH 30/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 72f5baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 29969d0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48ebef1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d4a18b7b0cc60e7d87bb884548b41d318547775d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 04:22:44 +0000 Subject: [PATCH 31/42] 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 | 1044 ---- .github/workflows/publish.yml | 261 - .github/workflows/publish_cli.yml | 184 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 50 files changed, 4862 insertions(+), 5694 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 befea45..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-02-02T02:37:45.139Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..86d9a9a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index 4f5887c..a791b67 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/process-read-stdin": "^0.2.2", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.3", - "@stdlib/string-base-last": "^0.1.2", - "@stdlib/string-base-last-code-point": "^0.1.2", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-regexp-from-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "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", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a532131 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From f7c4274d4c13aee398408299313793b544ae9256 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 19:54:58 +0000 Subject: [PATCH 32/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 6290749..1c72ca8 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.2", "@stdlib/string-base-last-code-point": "^0.1.2", "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/utils-regexp-from-string": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 15b5364809c16a4e1e2a363a31ff511088fd3bb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 20:51:13 +0000 Subject: [PATCH 33/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 72f5baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 86d9a9a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a532131..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1c653d041935b2383c757c92108606a8067f737b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 20:51:32 +0000 Subject: [PATCH 34/42] 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 | 1044 ---- .github/workflows/publish.yml | 261 - .github/workflows/publish_cli.yml | 184 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 49 files changed, 4862 insertions(+), 5686 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4fae580 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index 1c72ca8..139ae4a 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/assert-is-regexp-string": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/cli-ctor": "^0.2.3", - "@stdlib/fs-read-file": "^0.2.3", - "@stdlib/process-read-stdin": "^0.2.3", - "@stdlib/regexp-eol": "^0.2.3", - "@stdlib/streams-node-stdin": "^0.2.3", - "@stdlib/string-base-last": "^0.1.2", - "@stdlib/string-base-last-code-point": "^0.1.2", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/utils-regexp-from-string": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.3", - "@stdlib/assert-is-windows": "^0.2.3", - "@stdlib/process-exec-path": "^0.2.3", - "@stdlib/string-replace": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f8107ed --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 2dd4cb982449de64d44df388ecb132389126a3ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 21:31:28 +0000 Subject: [PATCH 35/42] Update README.md for ESM bundle v0.1.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c9d6a9..00cd1e5 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import last from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-last@esm/index.mjs'; +import last from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-last@v0.1.1-esm/index.mjs'; ``` #### last( str\[, n]\[, options] ) @@ -105,7 +105,7 @@ out = last( 'foo bar', 10 ); - - - - From e64dc9f89043e51eee4d350ed842f76073c16f32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Feb 2026 05:41:16 +0000 Subject: [PATCH 39/42] 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 | 1044 ---- .github/workflows/publish.yml | 261 - .github/workflows/publish_cli.yml | 184 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 50 files changed, 4862 insertions(+), 5687 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.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 98ca232..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-02-23T02:50:19.202Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..004c09f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index dff4ee4..139ae4a 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/assert-is-regexp-string": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/cli-ctor": "^0.2.3", - "@stdlib/fs-read-file": "^0.2.3", - "@stdlib/process-read-stdin": "^0.2.3", - "@stdlib/regexp-eol": "^0.2.3", - "@stdlib/streams-node-stdin": "^0.2.3", - "@stdlib/string-base-last": "^0.1.2", - "@stdlib/string-base-last-code-point": "^0.1.2", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/utils-regexp-from-string": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.3", - "@stdlib/assert-is-windows": "^0.2.3", - "@stdlib/process-exec-path": "^0.2.3", - "@stdlib/string-replace": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bc1d962 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -}); From 0af9b40459a96de181e36ad4f05c2fd73d42e49d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Apr 2026 03:32:32 +0000 Subject: [PATCH 40/42] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index 665558e..4f4275f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ).factory; var lastCodeUnit = require( '@stdlib/string-base-last' ); var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -88,7 +88,7 @@ function last( str ) { var n; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( 'null3F', str ) ); } opts = { 'mode': 'grapheme' @@ -102,23 +102,23 @@ function last( str ) { options = n; n = 1; } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } } else { // nargs > 2 n = arguments[ 1 ]; if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + throw new TypeError( format( 'null3X', n ) ); } options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } } if ( options ) { if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); } } } diff --git a/package.json b/package.json index 15793b8..dff4ee4 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@stdlib/string-base-last": "^0.1.2", "@stdlib/string-base-last-code-point": "^0.1.2", "@stdlib/string-base-last-grapheme-cluster": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/utils-regexp-from-string": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From f5415bc11e5969b185174f893abd8d9aff4dc071 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Apr 2026 03:45:28 +0000 Subject: [PATCH 41/42] Remove files --- index.d.ts | 118 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4965 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 72f5baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Specifies the type of characters to return (default: 'grapheme'). - * - * ## Notes - * - * - The following option values are supported: - * - * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). - */ - mode?: 'grapheme' | 'code_point' | 'code_unit'; -} - -/** -* Returns the last `n` characters of a string. -* -* @param str - input string -* @param n - number of characters to return -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', 2 ); -* // returns 'ng' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2, { -* 'mode': 'grapheme' -* }); -* // returns '🐰🐸' -*/ -declare function last( str: string, n: number, options?: Options ): string; - -/** -* Returns the last character of a string. -* -* @param str - input string -* @param options - options -* @returns updated string -* -* @example -* var out = last( 'last man standing', { -* 'mode': 'code_unit' -* }); -* // returns 'g' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', { -* 'mode': 'grapheme' -* }); -* // returns '🐸' -*/ -declare function last( str: string, options?: Options ): string; - -/** -* Returns the last character(s) of a string. -* -* @param str - input string -* @param n - number of characters to return (default: 1) -* @returns updated string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -declare function last( str: string, n?: number ): string; - - -// EXPORTS // - -export = last; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 004c09f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a3108c7..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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bc1d962..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 02856e96aabd8a0536b5884af08fb0ced156750a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Apr 2026 03:45:44 +0000 Subject: [PATCH 42/42] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 1044 ---- .github/workflows/publish.yml | 261 - .github/workflows/publish_cli.yml | 184 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 86 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 129 +- SECURITY.md | 5 - benchmark/benchmark.js | 145 - bin/cli | 130 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 111 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 131 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 389 -- test/test.js | 406 -- 50 files changed, 4862 insertions(+), 5698 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/publish_cli.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli 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 docs/usage.txt delete mode 100644 etc/cli_opts.json delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) 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/fixtures/stdin_error.js.txt delete mode 100644 test/test.cli.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b0c40df..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-05T03:24:06.329Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a16cf41..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/string/last) 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 6f056ca..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/string/last) 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 28ebebe..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: '46 10 * * 5' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -265,7 +162,7 @@ p ## 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]. @@ -338,7 +235,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. -[@stdlib/string/first]: https://github.com/stdlib-js/string-first +[@stdlib/string/first]: https://github.com/stdlib-js/string-first/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 372d526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var last = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ] ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=grapheme', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'grapheme' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_point', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=code_unit', function benchmark( b ) { - var values; - var opts; - var out; - var i; - - values = [ - 'beep boop', - 'foo bar', - 'xyz abc' - ]; - opts = { - 'mode': 'code_unit' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = last( values[ i%values.length ], opts ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 73e568a..0000000 --- a/bin/cli +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdin = require( '@stdlib/process-read-stdin' ); -var stdinStream = require( '@stdlib/streams-node-stdin' ); -var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP; -var isRegExpString = require( '@stdlib/assert-is-regexp-string' ); -var reFromString = require( '@stdlib/utils-regexp-from-string' ); -var last = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var split; - var flags; - var args; - var opts; - var cli; - var n; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - if ( flags.n ) { - n = parseInt( flags.n, 10 ); - } else { - n = 1; - } - opts = {}; - if ( flags.mode ) { - opts.mode = flags.mode; - } - - // Get any provided command-line arguments: - args = cli.args(); - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - if ( flags.split ) { - if ( !isRegExpString( flags.split ) ) { - flags.split = '/'+flags.split+'/'; - } - split = reFromString( flags.split ); - } else { - split = RE_EOL; - } - return stdin( onRead ); - } - try { - console.log( last( args[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead( error, data ) { - var lines; - var i; - if ( error ) { - return cli.error( error ); - } - lines = data.toString().split( split ); - - // Remove any trailing separators (e.g., trailing newline)... - if ( lines[ lines.length-1 ] === '' ) { - lines.pop(); - } - if ( lines.length ) { - try { - console.log( last( lines[ 0 ], n, opts ) ); // eslint-disable-line no-console - } catch ( error ) { - return cli.error( error ); - } - for ( i = 1; i < lines.length; i++ ) { - console.log( last( lines[ i ], n, opts ) ); // eslint-disable-line no-console - } - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index aaf1829..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last" -%% click B href "https://github.com/stdlib-js/string-last/tree/main" -%% click C href "https://github.com/stdlib-js/string-last/tree/production" -%% click D href "https://github.com/stdlib-js/string-last/tree/esm" -%% click E href "https://github.com/stdlib-js/string-last/tree/deno" -%% click F href "https://github.com/stdlib-js/string-last/tree/umd" -%% click G href "https://github.com/stdlib-js/string-last/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/last -[production-url]: https://github.com/stdlib-js/string-last/tree/production -[deno-url]: https://github.com/stdlib-js/string-last/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-last/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-last/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-last/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-last/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-last/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-last/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71e6b71..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import last from '../docs/types/index'; -export = last; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3f8a0fd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){ -var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,f=require('@stdlib/string-base-last/dist'),c=require('@stdlib/string-base-last-code-point/dist'),h=require('@stdlib/string-base-last-grapheme-cluster/dist'),a=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:f},q=p(u);function b(i){var e,n,t,r;if(!d(i))throw new TypeError(a('1vV3F',i));if(t={mode:"grapheme"},n=arguments.length,n===1)r=1;else if(n===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(a('1vV3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(a('1vV3X',r));if(e=arguments[2],!s(e))throw new TypeError(a('1vV2V',e))}if(e&&l(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(a('1vVE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b -});var y=v();module.exports=y; -/** @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 fbe52e1..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar lastCodeUnit = require( '@stdlib/string-base-last' );\nvar lastCodePoint = require( '@stdlib/string-base-last-code-point' );\nvar lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC30\uD83D\uDC38'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = last;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 last character(s) of a string.\n*\n* @module @stdlib/string-last\n*\n* @example\n* var last = require( '@stdlib/string-last' );\n*\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* out = last( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC38\uD83D\uDC35'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAe,QAAS,0BAA2B,EACnDC,EAAgB,QAAS,qCAAsC,EAC/DC,EAAsB,QAAS,2CAA4C,EAC3EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAMC,EAAM,CACpB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "lastCodeUnit", "lastCodePoint", "lastGraphemeCluster", "format", "MODES", "FCNS", "isMode", "last", "str", "options", "nargs", "opts", "n", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 20b38de..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( str[, n][, options] ) - Returns the last character(s) of a string. - - Parameters - ---------- - str: string - Input string. - - n: integer (optional) - Number of characters to return. Default: 1. - - options: Object (optional) - Options. - - options.mode: string (optional) - Type of characters to return. The following modes are supported: - - - grapheme: grapheme clusters. Appropriate for strings containing visual - characters which can span multiple Unicode code points (e.g., emoji). - - code_point: Unicode code points. Appropriate for strings containing - visual characters which are comprised of more than one Unicode code - unit (e.g., ideographic symbols and punctuation and mathematical - alphanumerics). - - code_unit': UTF-16 code units. Appropriate for strings containing - visual characters drawn from the basic multilingual plane (BMP) (e.g., - common characters, such as those from the Latin, Greek, and Cyrillic - alphabets). - - Default: 'grapheme'. - - Returns - ------- - out: string - Output string. - - Examples - -------- - > var out = {{alias}}( 'beep' ) - 'p' - > out = {{alias}}( 'Boop', 2 ) - 'op' - > out = {{alias}}( 'foo bar', 3 ) - 'bar' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d5f37d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,111 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 last = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - last( 'abc' ); // $ExpectType string - last( 'abc', 1 ); // $ExpectType string - last( 'abc', {} ); // $ExpectType string - last( 'abc', 1, {} ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - last( true ); // $ExpectError - last( false ); // $ExpectError - last( null ); // $ExpectError - last( undefined ); // $ExpectError - last( 5 ); // $ExpectError - last( [] ); // $ExpectError - last( {} ); // $ExpectError - last( ( x: number ): number => x ); // $ExpectError - - last( true, 1 ); // $ExpectError - last( false, 1 ); // $ExpectError - last( null, 1 ); // $ExpectError - last( undefined, 1 ); // $ExpectError - last( 5, 1 ); // $ExpectError - last( [], 1 ); // $ExpectError - last( {}, 1 ); // $ExpectError - last( ( x: number ): number => x, 1 ); // $ExpectError - - last( true, {} ); // $ExpectError - last( false, {} ); // $ExpectError - last( null, {} ); // $ExpectError - last( undefined, {} ); // $ExpectError - last( 5, {} ); // $ExpectError - last( [], {} ); // $ExpectError - last( {}, {} ); // $ExpectError - last( ( x: number ): number => x, {} ); // $ExpectError - - last( true, 1, {} ); // $ExpectError - last( false, 1, {} ); // $ExpectError - last( null, 1, {} ); // $ExpectError - last( undefined, 1, {} ); // $ExpectError - last( 5, 1, {} ); // $ExpectError - last( [], 1, {} ); // $ExpectError - last( {}, 1, {} ); // $ExpectError - last( ( x: number ): number => x, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid second argument... -{ - last( 'abc', true ); // $ExpectError - last( 'abc', false ); // $ExpectError - last( 'abc', null ); // $ExpectError - last( 'abc', '' ); // $ExpectError - last( 'abc', [] ); // $ExpectError - last( 'abc', ( x: number ): number => x ); // $ExpectError - - last( 'abc', true, {} ); // $ExpectError - last( 'abc', false, {} ); // $ExpectError - last( 'abc', null, {} ); // $ExpectError - last( 'abc', '', {} ); // $ExpectError - last( 'abc', [], {} ); // $ExpectError - last( 'abc', {}, {} ); // $ExpectError - last( 'abc', ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - last( 'abc', { 'mode': true } ); // $ExpectError - last( 'abc', { 'mode': false } ); // $ExpectError - last( 'abc', { 'mode': null } ); // $ExpectError - last( 'abc', { 'mode': '' } ); // $ExpectError - last( 'abc', { 'mode': [] } ); // $ExpectError - last( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - last( 'abc', 1, { 'mode': true } ); // $ExpectError - last( 'abc', 1, { 'mode': false } ); // $ExpectError - last( 'abc', 1, { 'mode': null } ); // $ExpectError - last( 'abc', 1, { 'mode': '' } ); // $ExpectError - last( 'abc', 1, { 'mode': [] } ); // $ExpectError - last( 'abc', 1, { 'mode': {} } ); // $ExpectError - last( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - last(); // $ExpectError - last( 'abc', 1, {}, {} ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 8e24879..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: last [options] [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --n num Number of characters to return. Default: 1. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 2ceae45..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "n", - "split", - "mode" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7e5e6b5..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var last = require( './../lib' ); - -console.log( last( 'last man standing' ) ); -// => 'g' - -console.log( last( 'presidential election' ) ); -// => 'n' - -console.log( last( 'javaScript' ) ); -// => 't' - -console.log( last( 'Hidden Treasures' ) ); -// => 's' - -console.log( last( 'The Last of the Mohicans', 8 ) ); -// => 'Mohicans' - -console.log( last( '🐶🐮🐷🐰🐸', 2 ) ); -// => '🐰🐸' - -console.log( last( '🐶🐮🐷🐰🐸', 10 ) ); -// => '🐶🐮🐷🐰🐸' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..004c09f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{factory as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last@v0.1.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-code-point@v0.1.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-last-grapheme-cluster@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var l=["grapheme","code_point","code_unit"],p={grapheme:d,code_point:o,code_unit:n},h=i(l);function j(i){var n,o,d,j;if(!e(i))throw new TypeError(m("null3F",i));if(d={mode:"grapheme"},1===(o=arguments.length))j=1;else if(2===o){if(t(j=arguments[1]))n=j,j=1;else if(!s(j))throw new TypeError(m("null3X",j))}else{if(!s(j=arguments[1]))throw new TypeError(m("null3X",j));if(!t(n=arguments[2]))throw new TypeError(m("null2V",n))}if(n&&r(n,"mode")&&(d.mode=n.mode,!h(d.mode)))throw new TypeError(m("nullE1","mode",l.join('", "'),d.mode));return p[d.mode](i,j)}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a3108c7 --- /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) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport lastCodeUnit from '@stdlib/string-base-last';\nimport lastCodePoint from '@stdlib/string-base-last-code-point';\nimport lastGraphemeCluster from '@stdlib/string-base-last-grapheme-cluster';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': lastGraphemeCluster,\n\t'code_point': lastCodePoint,\n\t'code_unit': lastCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the last character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} last argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = last( 'last man standing' );\n* // returns 'g'\n*\n* @example\n* var out = last( 'presidential election' );\n* // returns 'n'\n*\n* @example\n* var out = last( 'javaScript' );\n* // returns 't'\n*\n* @example\n* var out = last( 'Hidden Treasures' );\n* // returns 's'\n*\n* @example\n* var out = last( '🐶🐮🐷🐰🐸', 2 );\n* // returns '🐰🐸'\n*\n* @example\n* var out = last( 'foo bar', 3 );\n* // returns 'bar'\n*/\nfunction last( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'null3F', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'null3X', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'nullE1', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nexport default last;\n"],"names":["MODES","FCNS","grapheme","lastGraphemeCluster","code_point","lastCodePoint","code_unit","lastCodeUnit","isMode","contains","last","str","options","nargs","opts","n","isString","TypeError","format","mode","arguments","length","isPlainObject","isNonNegativeInteger","hasOwnProp","join"],"mappings":";;k6BAmCA,IAAIA,EAAQ,CAAE,WAAY,aAAc,aACpCC,EAAO,CACVC,SAAYC,EACZC,WAAcC,EACdC,UAAaC,GAEVC,EAASC,EAAUT,GA0CvB,SAASU,EAAMC,GACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAUL,GACf,MAAM,IAAIM,UAAWC,EAAQ,SAAUP,IAMxC,GAJAG,EAAO,CACNK,KAAQ,YAGM,KADfN,EAAQO,UAAUC,QAEjBN,EAAI,OACE,GAAe,IAAVF,GAEX,GAAKS,EADLP,EAAIK,UAAW,IAEdR,EAAUG,EACVA,EAAI,OACE,IAAMQ,EAAsBR,GAClC,MAAM,IAAIE,UAAWC,EAAQ,SAAUH,QAElC,CAEN,IAAMQ,EADNR,EAAIK,UAAW,IAEd,MAAM,IAAIH,UAAWC,EAAQ,SAAUH,IAGxC,IAAMO,EADNV,EAAUQ,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,SAAUN,GAExC,CACD,GAAKA,GACCY,EAAYZ,EAAS,UACzBE,EAAKK,KAAOP,EAAQO,MACdX,EAAQM,EAAKK,OAClB,MAAM,IAAIF,UAAWC,EAAQ,SAAU,OAAQlB,EAAMyB,KAAM,QAAUX,EAAKK,OAI7E,OAAOlB,EAAMa,EAAKK,MAAQR,EAAKI,EAChC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cd5cd64..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return the last character(s) of a string. -* -* @module @stdlib/string-last -* -* @example -* var last = require( '@stdlib/string-last' ); -* -* var out = last( 'last man standing' ); -* // returns 'g' -* -* out = last( 'Hidden Treasures' ); -* // returns 's' -* -* out = last( '🐮🐷🐸🐵', 2 ); -* // returns '🐸🐵' -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f4275f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var lastCodeUnit = require( '@stdlib/string-base-last' ); -var lastCodePoint = require( '@stdlib/string-base-last-code-point' ); -var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// VARIABLES // - -var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; -var FCNS = { - 'grapheme': lastGraphemeCluster, - 'code_point': lastCodePoint, - 'code_unit': lastCodeUnit -}; -var isMode = contains( MODES ); - - -// MAIN // - -/** -* Returns the last character(s) of a string. -* -* @param {string} str - input string -* @param {NonNegativeInteger} [n=1] - number of characters to return -* @param {Options} [options] - options -* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) -* @throws {TypeError} last argument must be a string -* @throws {TypeError} second argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {string} output string -* -* @example -* var out = last( 'last man standing' ); -* // returns 'g' -* -* @example -* var out = last( 'presidential election' ); -* // returns 'n' -* -* @example -* var out = last( 'javaScript' ); -* // returns 't' -* -* @example -* var out = last( 'Hidden Treasures' ); -* // returns 's' -* -* @example -* var out = last( '🐶🐮🐷🐰🐸', 2 ); -* // returns '🐰🐸' -* -* @example -* var out = last( 'foo bar', 3 ); -* // returns 'bar' -*/ -function last( str ) { - var options; - var nargs; - var opts; - var n; - - if ( !isString( str ) ) { - throw new TypeError( format( 'null3F', str ) ); - } - opts = { - 'mode': 'grapheme' - }; - nargs = arguments.length; - if ( nargs === 1 ) { - n = 1; - } else if ( nargs === 2 ) { - n = arguments[ 1 ]; - if ( isPlainObject( n ) ) { - options = n; - n = 1; - } else if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - } else { // nargs > 2 - n = arguments[ 1 ]; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'null3X', n ) ); - } - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - } - if ( options ) { - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isMode( opts.mode ) ) { - throw new TypeError( format( 'nullE1', 'mode', MODES.join( '", "' ), opts.mode ) ); - } - } - } - return FCNS[ opts.mode ]( str, n ); -} - - -// EXPORTS // - -module.exports = last; diff --git a/package.json b/package.json index dff4ee4..139ae4a 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Return the last character(s) of a string.", "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" - } - ], - "bin": { - "last": "./bin/cli" - }, - "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", @@ -39,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/assert-is-regexp-string": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/cli-ctor": "^0.2.3", - "@stdlib/fs-read-file": "^0.2.3", - "@stdlib/process-read-stdin": "^0.2.3", - "@stdlib/regexp-eol": "^0.2.3", - "@stdlib/streams-node-stdin": "^0.2.3", - "@stdlib/string-base-last": "^0.1.2", - "@stdlib/string-base-last-code-point": "^0.1.2", - "@stdlib/string-base-last-grapheme-cluster": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/utils-regexp-from-string": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.3", - "@stdlib/assert-is-windows": "^0.2.3", - "@stdlib/process-exec-path": "^0.2.3", - "@stdlib/string-replace": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bc1d962 --- /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/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 6a98399..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = false; - -proxyquire( fpath, { - '@stdlib/process-read-stdin': stdin -}); - -function stdin( clbk ) { - clbk( new Error( 'beep' ) ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 7b7d34c..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,389 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var replace = require( '@stdlib/string-replace' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last character of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface returns the last `n` characters of a string argument', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--n=2\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ep\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "beep\nboop"', - '|', - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'p\np\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream (return `n` characters)', opts, function test( t ) { - var cmd = [ - 'printf "foo\nbar"', - '|', - EXEC_PATH, - fpath, - '--n=2' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'oo\nar\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (string)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf \'foo\nbar\nbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode code_point' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'o\nr\nz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var cmd = [ - 'printf \'foo\tbar\tbaz\'', - '|', - EXEC_PATH, - fpath, - '--mode=foo' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); - t.end(); - } -}); - -tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5dc3f06..0000000 --- a/test/test.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 last = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof last, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a nonnegative integer (options)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3.14, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (second argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', { - 'mode': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 3, - null, - true, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - last( 'beep', 1, { - 'mode': value - }); - }; - } -}); - -tape( 'the function returns an empty string if provided an empty string', function test( t ) { - t.strictEqual( last( '' ), '', 'returns expected value' ); - t.strictEqual( last( '', 1 ), '', 'returns expected value' ); - t.strictEqual( last( '', {} ), '', 'returns expected value' ); - t.strictEqual( last( '', 1, {} ), '', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns the last character of a provided string', function test( t ) { - var out; - - out = last( 'hello world' ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( '!!!' ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( 'Hello' ); - t.strictEqual( out, 'o', 'returns expected value' ); - - out = last( 'अनुच्छेद' ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書' ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷' ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty string if provided zero as the second argument', function test( t ) { - var out; - - out = last( 'hello world', 0 ); - t.strictEqual( out, '', 'returns expected value' ); - - out = last( 'JavaScript', 0, {} ); - t.strictEqual( out, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (default)', function test( t ) { - var out; - - out = last( 'hello world', 1 ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7 ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1 ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2 ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1 ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1 ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1 ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1 ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=grapheme)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'grapheme' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '👉🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_point)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_point' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '🌷', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '🏿', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports returning the last `n` characters of a provided string (mode=code_unit)', function test( t ) { - var opts; - var out; - - opts = { - 'mode': 'code_unit' - }; - - out = last( 'hello world', 1, opts ); - t.strictEqual( out, 'd', 'returns expected value' ); - - out = last( 'hello world', 7, opts ); - t.strictEqual( out, 'o world', 'returns expected value' ); - - out = last( '!!!', 1, opts ); - t.strictEqual( out, '!', 'returns expected value' ); - - out = last( '!!!', 2, opts ); - t.strictEqual( out, '!!', 'returns expected value' ); - - out = last( 'अनुच्छेद', 1, opts ); - t.strictEqual( out, 'द', 'returns expected value' ); - - out = last( '六书/六書', 1, opts ); - t.strictEqual( out, '書', 'returns expected value' ); - - out = last( '🌷', 1, opts ); - t.strictEqual( out, '\udf37', 'returns expected value' ); - - out = last( '👉🏿', 1, opts ); - t.strictEqual( out, '\udfff', 'returns expected value' ); - - t.end(); -});